aboutsummaryrefslogtreecommitdiff
path: root/testes/utf8.lua
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2022-09-23 10:41:16 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2022-09-23 10:41:16 -0300
commita1089b415a3f5c753aa1b40758ffdaf28d5701b0 (patch)
treec2bc42dd8b83e33d3159e6cc7f28daa2d2204b53 /testes/utf8.lua
parentf8c4c4fcf2b2fed00b3c5b71c19cd64e539dee51 (diff)
downloadlua-a1089b415a3f5c753aa1b40758ffdaf28d5701b0.tar.gz
lua-a1089b415a3f5c753aa1b40758ffdaf28d5701b0.tar.bz2
lua-a1089b415a3f5c753aa1b40758ffdaf28d5701b0.zip
Bug: 'utf8.codes' accepts spurious continuation bytes
Diffstat (limited to 'testes/utf8.lua')
-rw-r--r--testes/utf8.lua12
1 files changed, 11 insertions, 1 deletions
diff --git a/testes/utf8.lua b/testes/utf8.lua
index 461e223c..7472cfd0 100644
--- a/testes/utf8.lua
+++ b/testes/utf8.lua
@@ -97,9 +97,15 @@ do -- error indication in utf8.len
97 assert(not a and b == p) 97 assert(not a and b == p)
98 end 98 end
99 check("abc\xE3def", 4) 99 check("abc\xE3def", 4)
100 check("汉字\x80", #("汉字") + 1)
101 check("\xF4\x9F\xBF", 1) 100 check("\xF4\x9F\xBF", 1)
102 check("\xF4\x9F\xBF\xBF", 1) 101 check("\xF4\x9F\xBF\xBF", 1)
102 -- spurious continuation bytes
103 check("汉字\x80", #("汉字") + 1)
104 check("\x80hello", 1)
105 check("hel\x80lo", 4)
106 check("汉字\xBF", #("汉字") + 1)
107 check("\xBFhello", 1)
108 check("hel\xBFlo", 4)
103end 109end
104 110
105-- errors in utf8.codes 111-- errors in utf8.codes
@@ -112,12 +118,16 @@ do
112 end 118 end
113 errorcodes("ab\xff") 119 errorcodes("ab\xff")
114 errorcodes("\u{110000}") 120 errorcodes("\u{110000}")
121 errorcodes("in\x80valid")
122 errorcodes("\xbfinvalid")
123 errorcodes("αλφ\xBFα")
115 124
116 -- calling interation function with invalid arguments 125 -- calling interation function with invalid arguments
117 local f = utf8.codes("") 126 local f = utf8.codes("")
118 assert(f("", 2) == nil) 127 assert(f("", 2) == nil)
119 assert(f("", -1) == nil) 128 assert(f("", -1) == nil)
120 assert(f("", math.mininteger) == nil) 129 assert(f("", math.mininteger) == nil)
130
121end 131end
122 132
123-- error in initial position for offset 133-- error in initial position for offset