Skip to content

Commit 830e6d2

Browse files
authored
Merge pull request webpack#7334 from gatimus/bugfix/json-byteordermark
fix: json with byte order mark
2 parents b93ae00 + 1b6bb85 commit 830e6d2

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

lib/JsonParser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class JsonParser {
1313
}
1414

1515
parse(source, state) {
16-
const data = parseJson(source);
16+
const data = parseJson(source[0] === "\ufeff" ? source.slice(1) : source);
1717
state.module.buildInfo.jsonData = data;
1818
state.module.buildMeta.exportsType = "named";
1919
if (typeof data === "object" && data)

test/cases/parsing/bom/bomfile.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "message": "ok" }

test/cases/parsing/bom/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ it("should load a css file with BOM", function() {
77
var css = require("!css-loader!./bomfile.css") + "";
88
expect(css).toBe("body{color:#abc}");
99
});
10+
11+
it("should load a json file with BOM", function() {
12+
var result = require("./bomfile.json");
13+
expect(result.message).toEqual("ok");
14+
});

0 commit comments

Comments
 (0)