|
1 | 1 | # This file is a part of Julia. License is MIT: https://julialang.org/license
|
2 | 2 |
|
3 | 3 | @testset "basic properties" begin
|
4 |
| - |
5 | 4 | @test typemax(Char) == reinterpret(Char, typemax(UInt32))
|
6 | 5 | @test typemin(Char) == Char(0)
|
7 | 6 | @test typemax(Char) == reinterpret(Char, 0xffffffff)
|
|
214 | 213 | end
|
215 | 214 | end
|
216 | 215 |
|
| 216 | +# issue #50532 |
| 217 | +@testset "invalid read(io, Char)" begin |
| 218 | + # byte values with different numbers of leading bits |
| 219 | + B = UInt8[ |
| 220 | + 0x3f, 0x4d, 0x52, 0x63, 0x81, 0x83, 0x89, 0xb6, |
| 221 | + 0xc0, 0xc8, 0xd3, 0xe3, 0xea, 0xeb, 0xf0, 0xf2, |
| 222 | + 0xf4, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, |
| 223 | + ] |
| 224 | + f = tempname() |
| 225 | + for b1 in B, b2 in B, t = 0:3 |
| 226 | + bytes = [b1, b2] |
| 227 | + append!(bytes, rand(B, t)) |
| 228 | + s = String(bytes) |
| 229 | + write(f, s) |
| 230 | + @test s == read(f, String) |
| 231 | + chars = collect(s) |
| 232 | + ios = [IOBuffer(s), open(f), Base.Filesystem.open(f, 0)] |
| 233 | + for io in ios |
| 234 | + chars′ = Char[] |
| 235 | + while !eof(io) |
| 236 | + push!(chars′, read(io, Char)) |
| 237 | + end |
| 238 | + @test chars == chars′ |
| 239 | + close(io) |
| 240 | + end |
| 241 | + end |
| 242 | + rm(f) |
| 243 | +end |
| 244 | + |
217 | 245 | @testset "overlong codes" begin
|
218 | 246 | function test_overlong(c::Char, n::Integer, rep::String)
|
219 | 247 | if isvalid(c)
|
|
0 commit comments