Skip to content
This repository was archived by the owner on Nov 4, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test for invalid utf8 in base64
  • Loading branch information
lydell committed Dec 28, 2019
commit 74d84c784315539a99b6dac88a48fef59beac637
31 changes: 29 additions & 2 deletions test/source-map-resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ var code = {
"foo.js%22%5D%2C%22names%22%3A%5B%5D%7D"),
base64: u("data:application/json;base64," +
"eyJtYXBwaW5ncyI6IkFBQUEiLCJzb3VyY2VzIjpbImZvby5qcyJdLCJzb3VyY2VzQ29udGVudCI6WyLkuK3mlofwn5iKIl0sIm5hbWVzIjpbXX0="), // jshint ignore:line
base64InvalidUtf8: u("data:application/json;base64,abc"),
dataUriText: u("data:text/json," +
"%7B%22mappings%22%3A%22AAAA%22%2C%22sources%22%3A%5B%22" +
"foo.js%22%5D%2C%22names%22%3A%5B%5D%7D"),
Expand All @@ -106,7 +107,7 @@ function testResolveSourceMap(method, sync) {

var codeUrl = "http://example.com/a/b/c/foo.js"

t.plan(1 + 12*3 + 7*4)
t.plan(1 + 12*3 + 8*4)

t.equal(typeof method, "function", "is a function")

Expand Down Expand Up @@ -186,6 +187,19 @@ function testResolveSourceMap(method, sync) {
isAsync()
})

method(code.base64InvalidUtf8, codeUrl, wrap(Throws), function(error, result) {
t.deepEqual(error.sourceMapData, {
sourceMappingURL: "data:application/json;base64,abc",
url: null,
sourcesRelativeTo: codeUrl,
map: "abc"
}, "base64InvalidUtf8 .sourceMapData")
t.ok(error instanceof TypeError && error.message !== "data:application/json;base64,abc",
"base64InvalidUtf8")
t.notOk(result)
isAsync()
})

method(code.dataUriText, codeUrl, wrap(Throws), function(error, result) {
t.error(error)
t.deepEqual(result, {
Expand Down Expand Up @@ -619,7 +633,7 @@ function testResolve(method, sync) {

var codeUrl = "http://example.com/a/b/c/foo.js"

t.plan(1 + 15*3 + 22*4 + 4)
t.plan(1 + 15*3 + 23*4 + 4)

t.equal(typeof method, "function", "is a function")

Expand Down Expand Up @@ -713,6 +727,19 @@ function testResolve(method, sync) {
isAsync()
})

method(code.base64InvalidUtf8, codeUrl, wrap(Throws), function(error, result) {
t.deepEqual(error.sourceMapData, {
sourceMappingURL: "data:application/json;base64,abc",
url: null,
sourcesRelativeTo: codeUrl,
map: "abc"
}, "base64InvalidUtf8 .sourceMapData")
t.ok(error instanceof TypeError && error.message !== "data:application/json;base64,abc",
"base64InvalidUtf8")
t.notOk(result)
isAsync()
})

method(code.dataUriText, codeUrl, wrapMap(Throws, identity), function(error, result) {
t.error(error)
t.deepEqual(result, {
Expand Down