Merge pull request #4163 from Rob--W/issue-4159-uri-annot
Recover from bad URI values
This commit is contained in:
		
						commit
						18a163c900
					
				@ -640,7 +640,13 @@ var LinkAnnotation = (function LinkAnnotationClosure() {
 | 
				
			|||||||
    if (action) {
 | 
					    if (action) {
 | 
				
			||||||
      var linkType = action.get('S').name;
 | 
					      var linkType = action.get('S').name;
 | 
				
			||||||
      if (linkType === 'URI') {
 | 
					      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
 | 
					        // TODO: pdf spec mentions urls can be relative to a Base
 | 
				
			||||||
        // entry in the dictionary.
 | 
					        // entry in the dictionary.
 | 
				
			||||||
        if (!isValidUrl(url, false)) {
 | 
					        if (!isValidUrl(url, false)) {
 | 
				
			||||||
 | 
				
			|||||||
@ -223,7 +223,7 @@ var UnsupportedManager = PDFJS.UnsupportedManager =
 | 
				
			|||||||
function combineUrl(baseUrl, url) {
 | 
					function combineUrl(baseUrl, url) {
 | 
				
			||||||
  if (!url)
 | 
					  if (!url)
 | 
				
			||||||
    return baseUrl;
 | 
					    return baseUrl;
 | 
				
			||||||
  if (url.indexOf(':') >= 0)
 | 
					  if (/^[a-z][a-z0-9+\-.]*:/i.test(url))
 | 
				
			||||||
    return url;
 | 
					    return url;
 | 
				
			||||||
  if (url.charAt(0) == '/') {
 | 
					  if (url.charAt(0) == '/') {
 | 
				
			||||||
    // absolute path
 | 
					    // absolute path
 | 
				
			||||||
@ -247,11 +247,13 @@ function isValidUrl(url, allowRelative) {
 | 
				
			|||||||
  if (!url) {
 | 
					  if (!url) {
 | 
				
			||||||
    return false;
 | 
					    return false;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  var colon = url.indexOf(':');
 | 
					  // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
 | 
				
			||||||
  if (colon < 0) {
 | 
					  // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
 | 
				
			||||||
 | 
					  var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
 | 
				
			||||||
 | 
					  if (!protocol) {
 | 
				
			||||||
    return allowRelative;
 | 
					    return allowRelative;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  var protocol = url.substr(0, colon);
 | 
					  protocol = protocol[0].toLowerCase();
 | 
				
			||||||
  switch (protocol) {
 | 
					  switch (protocol) {
 | 
				
			||||||
    case 'http':
 | 
					    case 'http':
 | 
				
			||||||
    case 'https':
 | 
					    case 'https':
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user