@@ -151,10 +151,8 @@ function HjsonDecoder:new(strict, object_hook, object_pairs_hook)
151151
152152 -- callers make sure that string starts with " or '
153153 local exitCh = charAt (s , begin )
154- while true do
155- :: scan_string_loop_start::
156- -- From hjson-py --> '(.*?)([\'"\\\x00-\x1f])'
157- local content , terminator = s :match (' (.-)([\' "\\ \x00 -\x1f ])' , _end )
154+ local function scan_string ()
155+ local content , terminator = s :match (' (.-)([\' "\\ %z\001 -\031 ])' , _end )
158156 if not content then
159157 decodeError (s , begin , " Unterminated string" )
160158 end
@@ -163,16 +161,16 @@ function HjsonDecoder:new(strict, object_hook, object_pairs_hook)
163161 chunks = chunks .. content
164162
165163 if terminator == exitCh then
166- break
164+ return false -- break
167165 elseif terminator == ' "' or terminator == " '" then
168166 chunks = chunks .. terminator
169- goto scan_string_loop_start
167+ return true -- continue
170168 elseif terminator ~= " \\ " then
171169 if strict then
172- decodeError (s , begin , " Invalid control character" .. terminator )
170+ decodeError (s , begin , " Invalid control character " .. terminator )
173171 else
174172 chunks = chunks .. terminator
175- goto scan_string_loop_start
173+ return true -- continue
176174 end
177175 end
178176
@@ -209,6 +207,7 @@ function HjsonDecoder:new(strict, object_hook, object_pairs_hook)
209207 end
210208 chunks = chunks .. chars
211209 end
210+ while scan_string () do end
212211 return chunks , _end
213212 end
214213
@@ -235,8 +234,7 @@ function HjsonDecoder:new(strict, object_hook, object_pairs_hook)
235234 end
236235
237236 -- When parsing multiline string values, we must look for ' characters
238- while true do
239- :: scan_mlstring_loop_start::
237+ local function scan_mlstring ()
240238 ch = charAt (s , _end )
241239 if ch == " " then
242240 decodeError (s , _end , " Bad multiline string" )
@@ -250,7 +248,7 @@ function HjsonDecoder:new(strict, object_hook, object_pairs_hook)
250248 end
251249 return string , _end
252250 else
253- goto scan_mlstring_loop_start
251+ return false
254252 end
255253 else
256254 while triple > 0 do
@@ -269,6 +267,12 @@ function HjsonDecoder:new(strict, object_hook, object_pairs_hook)
269267 _end = _end + 1
270268 end
271269 end
270+ while true do
271+ local s , _end = scan_mlstring ()
272+ if s then
273+ return s , _end
274+ end
275+ end
272276 end
273277
274278 local function parsePrimitive (s , _end )
@@ -286,7 +290,7 @@ function HjsonDecoder:new(strict, object_hook, object_pairs_hook)
286290 if
287291 isEol or ch == " ," or ch == " }" or ch == " ]" or ch == " #" or
288292 ch == " /" and (charAt (s , _end + 1 ) == " /" or charAt (s , _end + 1 ) == " *" )
289- then
293+ then
290294 local m = nil
291295 local integer = nil
292296 local frac = nil
0 commit comments