Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug handling CESU-8 strings in convert(UTF8String, Vector{UInt8} #12360

Merged
merged 2 commits into from
Jul 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions base/unicode/utf8.jl
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ function convert(::Type{UTF8String}, dat::Vector{UInt8})
buf[out += 1] = dat[pos += 1]
else
# Pick up surrogate pairs (CESU-8 format)
ch = (((((ch & 0x3f) << 6) | (dat[pos + 1] & 0x3f)) << 10)
+ (((dat[pos + 3] & 0x3f) << 6) | (dat[pos + 4] & 0x3f))
- 0xc00)
ch = ((((((ch & 0x3f) << 6) | (dat[pos + 1] & 0x3f)) << 10)
+ (((dat[pos + 3] & 0x3f)%UInt32 << 6) | (dat[pos + 4] & 0x3f)))
- 0x01f0c00)
pos += 4
output_utf8_4byte!(buf, out, ch)
out += 4
Expand Down
1 change: 1 addition & 0 deletions test/unicode.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

include("unicode/checkstring.jl")
include("unicode/utf8.jl")
include("unicode/utf16.jl")
include("unicode/utf32.jl")
include("unicode/utf8proc.jl")
12 changes: 12 additions & 0 deletions test/unicode/utf8.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

## Test for CESU-8 sequences

let ch = 0x10000
for hichar = 0xd800:0xdbff
for lochar = 0xdc00:0xdfff
@test convert(UTF8String, utf8(Char[hichar, lochar]).data) == string(Char(ch))
ch += 1
end
end
end