Skip to content

Commit f21fb80

Browse files
authored
Fix serialization of kinds with multibyte chars (#501)
This patch fixes serialization of `Kind`s to use `sizeof` (number of bytes) instead of `length` (number of characters) when computing number of bytes in the stringified `Kind`.
1 parent a3d1a6b commit f21fb80

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/kinds.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ end
6666
# can be serialized and deserialized across different JuliaSyntax versions.
6767
function Base.write(io::IO, k::Kind)
6868
str = convert(String, k)
69-
write(io, UInt8(length(str))) + write(io, str)
69+
write(io, UInt8(sizeof(str))) + write(io, str)
7070
end
7171
function Base.read(io::IO, ::Type{Kind})
7272
len = read(io, UInt8)

test/serialization.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ end
1919
end
2020

2121
@testset "Serialization $T" for T in [Expr, SyntaxNode, JuliaSyntax.GreenNode]
22-
x = JuliaSyntax.parsestmt(T, "f(x) = x + 2")
22+
x = JuliaSyntax.parsestmt(T, "f(x) = x 2")
2323
f = tempname()
2424
open(f, "w") do io
2525
serialize(io, x)

0 commit comments

Comments
 (0)