1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Merge pull request #6834 from Snuffleupagus/issue-6832

Strip `null` (\x00) characters from the URLs in LinkAnnotations (issue 6832)
This commit is contained in:
Tim van der Meij 2016-01-05 23:59:25 +01:00
commit 4399d01169
7 changed files with 33 additions and 25 deletions

View file

@ -33,6 +33,7 @@ var AnnotationType = sharedUtil.AnnotationType;
var Util = sharedUtil.Util;
var isExternalLinkTargetSet = sharedUtil.isExternalLinkTargetSet;
var LinkTargetStringMap = sharedUtil.LinkTargetStringMap;
var removeNullCharacters = sharedUtil.removeNullCharacters;
var warn = sharedUtil.warn;
var CustomStyle = displayDOMUtils.CustomStyle;
@ -232,7 +233,8 @@ var LinkAnnotationElement = (function LinkAnnotationElementClosure() {
this.container.className = 'linkAnnotation';
var link = document.createElement('a');
link.href = link.title = this.data.url || '';
link.href = link.title = (this.data.url ?
removeNullCharacters(this.data.url) : '');
if (this.data.url && isExternalLinkTargetSet()) {
link.target = LinkTargetStringMap[PDFJS.externalLinkTarget];

View file

@ -504,6 +504,16 @@ var XRefParseException = (function XRefParseExceptionClosure() {
return XRefParseException;
})();
var NullCharactersRegExp = /\x00/g;
function removeNullCharacters(str) {
if (typeof str !== 'string') {
warn('The argument for removeNullCharacters must be a string.');
return str;
}
return str.replace(NullCharactersRegExp, '');
}
PDFJS.removeNullCharacters = removeNullCharacters;
function bytesToString(bytes) {
assert(bytes !== null && typeof bytes === 'object' &&
@ -1690,6 +1700,7 @@ exports.log2 = log2;
exports.readInt8 = readInt8;
exports.readUint16 = readUint16;
exports.readUint32 = readUint32;
exports.removeNullCharacters = removeNullCharacters;
exports.shadow = shadow;
exports.string32 = string32;
exports.stringToBytes = stringToBytes;