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:
parent
a789368b7a
commit
99de25d6cc
2 changed files with 68 additions and 6 deletions
|
@ -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. */ }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue