Strip null (\x00) characters from the URLs in LinkAnnotations (issue 6832)

Apparently some PDF files can have annotations with `URI` entries ending with `null` characters, thus breaking the links.
To handle this edge-case of bad PDFs, this patch moves the already existing utility function from `ui_utils.js` into `util.js`, in order to fix those URLs.

Fixes 6832.
This commit is contained in:
Jonas Jenwald 2016-01-04 21:33:41 +01:00
parent 4e9ea35eee
commit 97c10e9c08
7 changed files with 33 additions and 25 deletions

View file

@ -1,5 +1,6 @@
/* globals expect, it, describe, combineUrl, Dict, isDict, Name, PDFJS,
stringToPDFString, isExternalLinkTargetSet, LinkTarget */
stringToPDFString, isExternalLinkTargetSet, LinkTarget,
removeNullCharacters */
'use strict';
@ -125,4 +126,16 @@ describe('util', function() {
// Reset the state.
PDFJS.externalLinkTarget = previousExternalLinkTarget;
});
describe('removeNullCharacters', function() {
it('should not modify string without null characters', function() {
var str = 'string without null chars';
expect(removeNullCharacters(str)).toEqual('string without null chars');
});
it('should modify string with null characters', function() {
var str = 'string\x00With\x00Null\x00Chars';
expect(removeNullCharacters(str)).toEqual('stringWithNullChars');
});
});
});