Skip to content

Commit b9fa5e5

Browse files
committed
Add sanitizeUrl tests
1 parent afa615e commit b9fa5e5

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

test/core/utils.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import {
1616
fromJSOrdered,
1717
getAcceptControllingResponse,
1818
createDeepLinkPath,
19-
escapeDeepLinkPath
19+
escapeDeepLinkPath,
20+
sanitizeUrl
2021
} from "core/utils"
2122
import win from "core/window"
2223

@@ -885,4 +886,31 @@ describe("utils", function() {
885886
expect(result).toEqual("hello\\#world")
886887
})
887888
})
889+
890+
describe.only("sanitizeUrl", function() {
891+
it("should sanitize a `javascript:` url", function() {
892+
const res = sanitizeUrl("javascript:alert('bam!')")
893+
894+
expect(res).toEqual("about:blank")
895+
})
896+
897+
it("should sanitize a `data:` url", function() {
898+
const res = sanitizeUrl(`data:text/html;base64,PHNjcmlwdD5hbGVydCgiSGV
899+
sbG8iKTs8L3NjcmlwdD4=`)
900+
901+
expect(res).toEqual("about:blank")
902+
})
903+
904+
it("should not modify a `http:` url", function() {
905+
const res = sanitizeUrl(`http://swagger.io/`)
906+
907+
expect(res).toEqual("http://swagger.io/")
908+
})
909+
910+
it("should not modify a `https:` url", function() {
911+
const res = sanitizeUrl(`https://swagger.io/`)
912+
913+
expect(res).toEqual("https://swagger.io/")
914+
})
915+
})
888916
})

0 commit comments

Comments
 (0)