Skip to content

Commit

Permalink
Fix serialization of kinds with multibyte chars (#501)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
fredrikekre authored Sep 11, 2024
1 parent a3d1a6b commit f21fb80
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/kinds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ end
# can be serialized and deserialized across different JuliaSyntax versions.
function Base.write(io::IO, k::Kind)
str = convert(String, k)
write(io, UInt8(length(str))) + write(io, str)
write(io, UInt8(sizeof(str))) + write(io, str)
end
function Base.read(io::IO, ::Type{Kind})
len = read(io, UInt8)
Expand Down
2 changes: 1 addition & 1 deletion test/serialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ end
end

@testset "Serialization $T" for T in [Expr, SyntaxNode, JuliaSyntax.GreenNode]
x = JuliaSyntax.parsestmt(T, "f(x) = x + 2")
x = JuliaSyntax.parsestmt(T, "f(x) = x 2")
f = tempname()
open(f, "w") do io
serialize(io, x)
Expand Down

0 comments on commit f21fb80

Please sign in to comment.