Try to recover from bad URI value

See https://github.com/mozilla/pdf.js/issues/4159

BAD (http://cms.di.unipi.it/files/bbec7791fac20e98127c77531e4031912392156c/testo.pdf)
<< /S /URI /URI /v#2findex.php#2fFile:Logo.png >>

GOOD (http://www.ioi2012.org/wp-content/uploads/2011/12/practice.pdf):
<< /S /URI /URI (http://127.0.0.1/v/index.php/File:Logo.png >>

The URL should be wrapped in parentheses, but sometimes it isn't.
Consequently, the value is interpreted as a Name (because of the leading "/"),
and the resulting object is `{name: "v/index.php/File:Logo.png" }`. Obviously,
this is not a string, so `url.indexOf` throws an error here.
This commit is contained in:
Rob Wu 2014-01-22 12:27:44 +01:00
parent 2c34807fa3
commit 3c0b8073be

View File

@ -640,7 +640,13 @@ var LinkAnnotation = (function LinkAnnotationClosure() {
if (action) {
var linkType = action.get('S').name;
if (linkType === 'URI') {
var url = addDefaultProtocolToUrl(action.get('URI'));
var url = action.get('URI');
if (isName(url)) {
// Some bad PDFs do not put parentheses around relative URLs.
url = '/' + url.name;
} else {
url = addDefaultProtocolToUrl(url);
}
// TODO: pdf spec mentions urls can be relative to a Base
// entry in the dictionary.
if (!isValidUrl(url, false)) {