mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 01:58:06 +02:00
[api-minor] Use the new URL
constructor when validating URLs in annotations and the outline, as a complement to only checking the protocol, and add a bit more validation to Catalog_parseDestDictionary
Note that this will automatically reject any relative URL. To make the API more useful to consumers, URLs that are rejected will be available via the `unsafeUrl` property in the data object returned by `PDFPageProxy_getAnnotations`. The patch also adds a bit more validation of the data for `Named` actions.
This commit is contained in:
parent
e64bc1fd13
commit
42f07c6262
3 changed files with 73 additions and 13 deletions
|
@ -275,6 +275,8 @@ describe('Annotation layer', function() {
|
|||
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
||||
|
||||
expect(data.url).toEqual('http://www.ctan.org/tex-archive/info/lshort');
|
||||
expect(data.unsafeUrl).toEqual(
|
||||
'http://www.ctan.org/tex-archive/info/lshort');
|
||||
expect(data.dest).toBeUndefined();
|
||||
});
|
||||
|
||||
|
@ -299,7 +301,8 @@ describe('Annotation layer', function() {
|
|||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
||||
|
||||
expect(data.url).toEqual('http://www.hmrc.gov.uk');
|
||||
expect(data.url).toEqual('http://www.hmrc.gov.uk/');
|
||||
expect(data.unsafeUrl).toEqual('http://www.hmrc.gov.uk');
|
||||
expect(data.dest).toBeUndefined();
|
||||
});
|
||||
|
||||
|
@ -331,6 +334,8 @@ describe('Annotation layer', function() {
|
|||
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
||||
|
||||
expect(data.url).toEqual(
|
||||
new URL(stringToUTF8String('http://www.example.com/üöä')).href);
|
||||
expect(data.unsafeUrl).toEqual(
|
||||
stringToUTF8String('http://www.example.com/üöä'));
|
||||
expect(data.dest).toBeUndefined();
|
||||
});
|
||||
|
@ -356,6 +361,7 @@ describe('Annotation layer', function() {
|
|||
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
||||
|
||||
expect(data.url).toBeUndefined();
|
||||
expect(data.unsafeUrl).toBeUndefined();
|
||||
expect(data.dest).toEqual('page.157');
|
||||
});
|
||||
|
||||
|
@ -382,7 +388,8 @@ describe('Annotation layer', function() {
|
|||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
||||
|
||||
expect(data.url).toBeUndefined(); // ../../0013/001346/134685E.pdf#4.3
|
||||
expect(data.url).toBeUndefined();
|
||||
expect(data.unsafeUrl).toEqual('../../0013/001346/134685E.pdf#4.3');
|
||||
expect(data.dest).toBeUndefined();
|
||||
expect(data.newWindow).toEqual(true);
|
||||
});
|
||||
|
@ -410,6 +417,8 @@ describe('Annotation layer', function() {
|
|||
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
||||
|
||||
expect(data.url).toEqual('http://www.example.com/test.pdf#nameddest=15');
|
||||
expect(data.unsafeUrl).toEqual(
|
||||
'http://www.example.com/test.pdf#nameddest=15');
|
||||
expect(data.dest).toBeUndefined();
|
||||
expect(data.newWindow).toBeFalsy();
|
||||
});
|
||||
|
@ -436,8 +445,10 @@ describe('Annotation layer', function() {
|
|||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
||||
|
||||
expect(data.url).toEqual('http://www.example.com/test.pdf#' +
|
||||
'[14,{"name":"XYZ"},null,298.043,null]');
|
||||
expect(data.url).toEqual(new URL('http://www.example.com/test.pdf#' +
|
||||
'[14,{"name":"XYZ"},null,298.043,null]').href);
|
||||
expect(data.unsafeUrl).toEqual('http://www.example.com/test.pdf#' +
|
||||
'[14,{"name":"XYZ"},null,298.043,null]');
|
||||
expect(data.dest).toBeUndefined();
|
||||
expect(data.newWindow).toBeFalsy();
|
||||
});
|
||||
|
@ -463,6 +474,7 @@ describe('Annotation layer', function() {
|
|||
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
||||
|
||||
expect(data.url).toBeUndefined();
|
||||
expect(data.unsafeUrl).toBeUndefined();
|
||||
expect(data.action).toEqual('GoToPage');
|
||||
});
|
||||
|
||||
|
@ -482,8 +494,32 @@ describe('Annotation layer', function() {
|
|||
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
||||
|
||||
expect(data.url).toBeUndefined();
|
||||
expect(data.unsafeUrl).toBeUndefined();
|
||||
expect(data.dest).toEqual('LI0');
|
||||
});
|
||||
|
||||
it('should correctly parse a simple Dest, with explicit destination array',
|
||||
function() {
|
||||
var annotationDict = new Dict();
|
||||
annotationDict.set('Type', Name.get('Annot'));
|
||||
annotationDict.set('Subtype', Name.get('Link'));
|
||||
annotationDict.set('Dest', [new Ref(17, 0), Name.get('XYZ'),
|
||||
0, 841.89, null]);
|
||||
|
||||
var annotationRef = new Ref(10, 0);
|
||||
var xref = new XRefMock([
|
||||
{ ref: annotationRef, data: annotationDict, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, annotationRef);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
||||
|
||||
expect(data.url).toBeUndefined();
|
||||
expect(data.unsafeUrl).toBeUndefined();
|
||||
expect(data.dest).toEqual([{ num: 17, gen: 0, }, { name: 'XYZ' },
|
||||
0, 841.89, null]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('TextWidgetAnnotation', function() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue