mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-25 09:38:06 +02:00
XFA - Add <a> element in button when an url is detected (bug 1716758)
- it aims to fix https://bugzilla.mozilla.org/show_bug.cgi?id=1716758; - some buttons have a JS action with the pattern `app.launchURL(...)` (or similar) so extract when it's possible the url and generate a <a> element with the href equals to the found url; - pdf.js already had some code to handle that so this patch slightly refactor that.
This commit is contained in:
parent
3b1d547738
commit
558e58f354
8 changed files with 173 additions and 44 deletions
|
@ -467,6 +467,34 @@ function tryConvertUrlEncoding(url) {
|
|||
}
|
||||
}
|
||||
|
||||
function recoverJsURL(str) {
|
||||
// Attempt to recover valid URLs from `JS` entries with certain
|
||||
// white-listed formats:
|
||||
// - window.open('http://example.com')
|
||||
// - app.launchURL('http://example.com', true)
|
||||
// - xfa.host.gotoURL('http://example.com')
|
||||
const URL_OPEN_METHODS = ["app.launchURL", "window.open", "xfa.host.gotoURL"];
|
||||
const regex = new RegExp(
|
||||
"^\\s*(" +
|
||||
URL_OPEN_METHODS.join("|").split(".").join("\\.") +
|
||||
")\\((?:'|\")([^'\"]*)(?:'|\")(?:,\\s*(\\w+)\\)|\\))",
|
||||
"i"
|
||||
);
|
||||
|
||||
const jsUrl = regex.exec(str);
|
||||
if (jsUrl && jsUrl[2]) {
|
||||
const url = jsUrl[2];
|
||||
let newWindow = false;
|
||||
|
||||
if (jsUrl[3] === "true" && jsUrl[1] === "app.launchURL") {
|
||||
newWindow = true;
|
||||
}
|
||||
return { url, newWindow };
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export {
|
||||
addDefaultProtocolToUrl,
|
||||
collectActions,
|
||||
|
@ -483,6 +511,7 @@ export {
|
|||
readInt8,
|
||||
readUint16,
|
||||
readUint32,
|
||||
recoverJsURL,
|
||||
toRomanNumerals,
|
||||
tryConvertUrlEncoding,
|
||||
validateCSSFont,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue