From: Brendan Dahl Date: Mon, 12 Mar 2012 23:31:49 +0000 (-0700) Subject: Add function for checking url. X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=084a8bca031bf8d7aff49f51083afac5b0d5c503;p=pdf.js.git Add function for checking url. --- diff --git a/src/core.js b/src/core.js index 341cf64..90a7eda 100644 --- a/src/core.js +++ b/src/core.js @@ -310,6 +310,22 @@ var Page = (function PageClosure() { return null; return item.get(name); } + function isValidUrl(url) { + if (!url) + return false; + var colon = url.indexOf(':'); + if (colon < 0) + return false; + var protocol = url.substr(0, colon); + switch (protocol) { + case 'http': + case 'https': + case 'ftp': + return true; + default: + return false; + } + } var annotations = xref.fetchIfRef(this.annotations) || []; var i, n = annotations.length; @@ -341,8 +357,7 @@ var Page = (function PageClosure() { var url = a.get('URI'); // TODO: pdf spec mentions urls can be relative to a Base // entry in the dictionary. - // For now only allow http and https schemes. - if (url.search(/^https?\:/) !== 0) + if (!isValidUrl(url)) url = ''; item.url = url; break;