Skip to content

Commit 45be85e

Browse files
committed
Fix out-out-bounds access in unsafeCodePointAt0Fallback
`unsafeCodePointAt0Fallback` crashed when passed a string of length 1 due to always accessing index 1.
1 parent 9d4387e commit 45be85e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/Data/String/CodePoints.purs

+6-4
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,10 @@ unsafeCodePointAt0Fallback :: String -> CodePoint
415415
unsafeCodePointAt0Fallback s =
416416
let
417417
cu0 = fromEnum (Unsafe.charAt 0 s)
418-
cu1 = fromEnum (Unsafe.charAt 1 s)
419418
in
420-
if isLead cu0 && isTrail cu1
421-
then unsurrogate cu0 cu1
422-
else CodePoint cu0
419+
if isLead cu0 && CU.length s > 1
420+
then
421+
let cu1 = fromEnum (Unsafe.charAt 1 s) in
422+
if isTrail cu1 then unsurrogate cu0 cu1 else CodePoint cu0
423+
else
424+
CodePoint cu0

0 commit comments

Comments
 (0)