Skip to content

Commit

Permalink
Bug: Error when survey finish to "navigateToUrl" fix #8631 (#8633)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov authored Aug 1, 2024
1 parent 29572ae commit b0ba118
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function scrollElementByChildId(id: string) {
function navigateToUrl(url: string): void {
const location = DomWindowHelper.getLocation();
if (!url || !location) return;
location.href = encodeURIComponent(url);
location.href = getSafeUrl(url);
}

function wrapUrlForBackgroundImage(url: string): string {
Expand Down Expand Up @@ -205,6 +205,11 @@ function createSvg(
}
titleElement.textContent = title;
}
export function getSafeUrl(url: string): string {
if(!url) return url;
if(url.toLocaleLowerCase().indexOf("javascript:")> -1) return encodeURIComponent(url);
return url;
}

export function unwrap<T>(value: T | (() => T)): T {
if (typeof value !== "function") {
Expand Down
6 changes: 5 additions & 1 deletion tests/utilstests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IAction } from "../src/actions/action";
import { defaultListCss } from "../src/list";
import { createSvg, doKey2ClickDown, doKey2ClickUp, sanitizeEditableContent, configConfirmDialog, mergeValues, compareArrays } from "../src/utils/utils";
import { createSvg, doKey2ClickDown, doKey2ClickUp, sanitizeEditableContent, configConfirmDialog, getSafeUrl, compareArrays } from "../src/utils/utils";
import { mouseInfo, detectMouseSupport, MatchMediaMethod } from "../src/utils/devices";
import { PopupBaseViewModel } from "../src/popup-view-model";
import { PopupModel } from "../src/popup";
Expand Down Expand Up @@ -1035,4 +1035,8 @@ QUnit.test("test onNextRender function", (assert) => {

window.requestAnimationFrame = oldRequestAnimationFrame;
window.cancelAnimationFrame = oldCancelAnimationFrame;
});
QUnit.test("getSafeUrl", (assert) => {
assert.equal(getSafeUrl("https://surveyjs.io"), "https://surveyjs.io", "https://surveyjs.io");
assert.equal(getSafeUrl("javascript:alert('1')"), "javascript%3Aalert('1')", "javascript:alert('1')");
});

0 comments on commit b0ba118

Please sign in to comment.