Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
7d5a49d5
Unverified
Commit
7d5a49d5
authored
Nov 07, 2017
by
Sean Hammond
Committed by
GitHub
Nov 07, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #563 from hypothesis/pdf-page-index-bounds-check
Add missing page index bounds check
parents
e4fb57cb
a2336a7c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
33 deletions
+25
-33
pdf.coffee
src/annotator/anchoring/pdf.coffee
+2
-1
pdf-test.js
src/annotator/anchoring/test/pdf-test.js
+23
-32
No files found.
src/annotator/anchoring/pdf.coffee
View file @
7d5a49d5
...
@@ -97,7 +97,8 @@ findPage = (offset) ->
...
@@ -97,7 +97,8 @@ findPage = (offset) ->
# 150 | 2
# 150 | 2
#
#
count
=
(
textContent
)
->
count
=
(
textContent
)
->
if
total
+
textContent
.
length
>
offset
lastPageIndex
=
PDFViewerApplication
.
pdfViewer
.
pagesCount
-
1
if
total
+
textContent
.
length
>
offset
or
index
==
lastPageIndex
offset
=
total
offset
=
total
return
Promise
.
resolve
({
index
,
offset
,
textContent
})
return
Promise
.
resolve
({
index
,
offset
,
textContent
})
else
else
...
...
src/annotator/anchoring/test/pdf-test.js
View file @
7d5a49d5
...
@@ -35,7 +35,7 @@ var fixtures = {
...
@@ -35,7 +35,7 @@ var fixtures = {
],
],
};
};
describe
(
'
PDF anchoring
'
,
function
()
{
describe
(
'
annotator.anchoring.pdf
'
,
function
()
{
var
container
;
var
container
;
var
viewer
;
var
viewer
;
...
@@ -166,39 +166,30 @@ describe('PDF anchoring', function () {
...
@@ -166,39 +166,30 @@ describe('PDF anchoring', function () {
});
});
});
});
it
(
'anchors using a quote if the position anchor fails'
,
function
()
{
[{
viewer
.
setCurrentPage
(
0
);
// Position on same page as quote but different text.
var
range
=
findText
(
container
,
'Pride And Prejudice'
);
offset
:
5
,
return
pdfAnchoring
.
describe
(
container
,
range
).
then
(
function
(
selectors
)
{
},{
var
position
=
selectors
[
0
];
// Position on a different page to the quote.
var
quote
=
selectors
[
1
];
offset
:
fixtures
.
pdfPages
[
0
].
length
+
10
,
},{
// Manipulate the position selector so that it is no longer valid.
// Position invalid for document.
// Anchoring should fall back to the quote selector instead.
offset
:
100000
,
position
.
start
+=
5
;
}].
forEach
(({
offset
})
=>
{
position
.
end
+=
5
;
it
(
'anchors using a quote if the position selector fails'
,
function
()
{
viewer
.
setCurrentPage
(
0
);
return
pdfAnchoring
.
anchor
(
container
,
[
position
,
quote
]);
var
range
=
findText
(
container
,
'Pride And Prejudice'
);
}).
then
(
function
(
range
)
{
return
pdfAnchoring
.
describe
(
container
,
range
).
then
(
function
(
selectors
)
{
assert
.
equal
(
range
.
toString
(),
'Pride And Prejudice'
);
var
position
=
selectors
[
0
];
});
var
quote
=
selectors
[
1
];
});
it
(
'anchors using a quote if the position selector refers to the wrong page'
,
function
()
{
viewer
.
setCurrentPage
(
0
);
var
range
=
findText
(
container
,
'Pride And Prejudice'
);
return
pdfAnchoring
.
describe
(
container
,
range
).
then
(
function
(
selectors
)
{
var
position
=
selectors
[
0
];
var
quote
=
selectors
[
1
];
// Manipulate the position selector so that it refers to a location
position
.
start
+=
offset
;
// a long way away, on a different page, than the quote.
position
.
end
+=
offset
;
position
.
start
+=
fixtures
.
pdfPages
[
0
].
length
+
10
;
position
.
end
+=
fixtures
.
pdfPages
[
0
].
length
+
10
;
return
pdfAnchoring
.
anchor
(
container
,
[
position
,
quote
]);
return
pdfAnchoring
.
anchor
(
container
,
[
position
,
quote
]);
}).
then
(
function
(
range
)
{
}).
then
(
range
=>
{
assert
.
equal
(
range
.
toString
(),
'Pride And Prejudice'
);
assert
.
equal
(
range
.
toString
(),
'Pride And Prejudice'
);
});
});
});
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment