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

Implement unit tests for the isSameOrigin and createValidAbsoluteUrl utility functions

Moreover, mark the `isValidProtocol` function as private since it's only
used in the utilities file and is not (meant to be) exported.
This commit is contained in:
Tim van der Meij 2018-09-11 15:16:07 +02:00
parent a789368b7a
commit 99de25d6cc
No known key found for this signature in database
GPG key ID: 8C3FD2925A5F2762
2 changed files with 68 additions and 6 deletions

View file

@ -332,7 +332,7 @@ function isSameOrigin(baseUrl, otherUrl) {
}
// Checks if URLs use one of the whitelisted protocols, e.g. to avoid XSS.
function isValidProtocol(url) {
function _isValidProtocol(url) {
if (!url) {
return false;
}
@ -349,7 +349,8 @@ function isValidProtocol(url) {
}
/**
* Attempts to create a valid absolute URL (utilizing `isValidProtocol`).
* Attempts to create a valid absolute URL.
*
* @param {URL|string} url - An absolute, or relative, URL.
* @param {URL|string} baseUrl - An absolute URL.
* @returns Either a valid {URL}, or `null` otherwise.
@ -360,7 +361,7 @@ function createValidAbsoluteUrl(url, baseUrl) {
}
try {
var absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url);
if (isValidProtocol(absoluteUrl)) {
if (_isValidProtocol(absoluteUrl)) {
return absoluteUrl;
}
} catch (ex) { /* `new URL()` will throw on incorrect data. */ }