Skip to content

Commit 94c843b

Browse files
authored
Merge pull request #112 from restaumatic/fix-codePointAt-fallback
Fix out of bounds access in `unsafeCodePointAt0Fallback`
2 parents 586307d + 45be85e commit 94c843b

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"scripts": {
44
"clean": "rimraf output && rimraf .pulp-cache",
55
"build": "eslint src && pulp build -- --censor-lib --strict",
6-
"test": "pulp test",
6+
"test": "pulp test && npm run test:run:without_codePointAt",
7+
"test:run:without_codePointAt": "node -e \"delete String.prototype.codePointAt; require('./output/Test.Main/index.js').main();\"",
78
"bench:build": "purs compile 'bench/**/*.purs' 'src/**/*.purs' 'bower_components/*/src/**/*.purs'",
89
"bench:run": "node --expose-gc -e 'require(\"./output/Bench.Main/index.js\").main()'",
910
"bench": "npm run bench:build && npm run bench:run"

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)