Skip to content
This repository was archived by the owner on Jan 1, 2023. It is now read-only.

Commit c3c7415

Browse files
committed
🐛 fix bug
1 parent 32d8616 commit c3c7415

File tree

3 files changed

+3
-1
lines changed

3 files changed

+3
-1
lines changed

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const createSafeStringForJsonParse = (value: string) => {
7474
const codes = ['\f', '\r', '\n', '\t', '\b']
7575
const replaceCodes = ['\\f', '\\r', '\\n', '\\t', '\\b']
7676
for (let i = 0; i < codes.length; i++) {
77-
value = value.replace(new RegExp(codes[i]), replaceCodes[i])
77+
value = value.replace(new RegExp(codes[i], 'g'), replaceCodes[i])
7878
}
7979
}
8080

test/__fixtures__/object/backslash/input.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const test21 = { 'fo\r\no': "foo" }
2222
const test22 = { 'fo\\o': "foo" }
2323
const test23 = { 'fo\\\o': "foo" }
2424
const test24 = { 'fo\\\\o': "foo" }
25+
const test25 = { foo: 'foo\nbar\nhoge' }
2526
const res = [
2627
test1,
2728
test2,

test/__fixtures__/object/backslash/output.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const test21 = JSON.parse('{"fo\\r\\no":"foo"}')
2222
const test22 = JSON.parse('{"fo\\\\o":"foo"}')
2323
const test23 = JSON.parse('{"fo\\\\o":"foo"}')
2424
const test24 = JSON.parse('{"fo\\\\\\\\o":"foo"}')
25+
const test25 = JSON.parse('{"foo":"foo\\nbar\\nhoge"}')
2526
const res = [
2627
test1,
2728
test2,

0 commit comments

Comments
 (0)