FIX: Validate asset url before replacing base url (#16438)

Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
This commit is contained in:
Zachary Huff 2023-01-29 18:32:48 -05:00 committed by GitHub
parent cd55d72b61
commit 0a8387ecd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -38,7 +38,7 @@ export function getURLWithCDN(url) {
// only relative urls
if (cdn && /^\/[^\/]/.test(url)) {
url = cdn + url;
} else if (S3CDN) {
} else if (S3CDN && url.startsWith(S3BaseUrl)) {
url = url.replace(S3BaseUrl, S3CDN);
}
return url;

View File

@ -172,4 +172,12 @@ module("Unit | Utility | get-url", function () {
assert.strictEqual(getURLWithCDN(url), expected, "at correct path");
});
test("getURLWithCDN when URL includes protocol", function (assert) {
setupS3CDN("//awesome.cdn/site", "https://awesome.cdn/site");
let url = "https://awesome.cdn/site/awesome.png";
assert.strictEqual(getURLWithCDN(url), url, "at correct path");
});
});