Skip to content

Commit b2787c3

Browse files
authored
[JSONX] Fix unicode handling when unescaping strings (#405)
Previously `JSONX.unescape_string()` would insert single codeunits at a time into the unescaped output (if the current character is not an escape sequence). This caused characters composed of multiple codeunits to be unescaped as individual characters.
1 parent 52d8b90 commit b2787c3

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

vendor/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,9 @@ Compared to the full JSON.jl package, JSONX is intentionally simplified:
9696
- **Error robust**: Comprehensive error checking and reporting
9797

9898
Note: Functions are not exported, so use `JSONX.parse` and `JSONX.json` with the module prefix.
99+
100+
## Changelog
101+
102+
- Fixed unicode handling when unescaping strings (https://github.com/JuliaIO/JSON.jl/pull/405).
103+
- **Breaking**: Added support for parsing Int64's (https://github.com/JuliaIO/JSON.jl/pull/396).
104+
- Added `JSONText` (https://github.com/JuliaIO/JSON.jl/pull/394).

vendor/jsonx.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,14 @@ function unescape_string(str::String, start_pos::Int, end_pos::Int)
138138
b == 0x00 && throw(ArgumentError("Invalid escape sequence \\$(Char(esc_c))"))
139139
print(io, Char(b))
140140
end
141+
142+
pos += 1
141143
else
142-
print(io, Char(c))
144+
# Regular character
145+
print(io, str[pos])
146+
pos = nextind(str, pos)
143147
end
144-
pos += 1
148+
145149
end
146150
return String(take!(io))
147151
end

vendor/test.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ include("jsonx.jl")
264264
@test JSONX.parse("\"\\uD83C\\uDF55\"") == "🍕" # Pizza emoji
265265
# Mixed content
266266
@test JSONX.parse("\"Hello \\u0041\\u006E\\u0064\\u0072\\u0065\\u0077!\"") == "Hello Andrew!"
267+
# String unescaping
268+
@test JSONX.parse(raw"\"𝔸\\a\"") == "𝔸\\a"
267269
# Writing Unicode
268270
@test JSONX.json("A") == "\"A\""
269271
@test JSONX.json("😀") == "\"😀\""

0 commit comments

Comments
 (0)