Skip to content

Commit

Permalink
Merge pull request #112 from restaumatic/fix-codePointAt-fallback
Browse files Browse the repository at this point in the history
Fix out of bounds access in `unsafeCodePointAt0Fallback`
  • Loading branch information
garyb authored Nov 11, 2018
2 parents 586307d + 45be85e commit 94c843b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"scripts": {
"clean": "rimraf output && rimraf .pulp-cache",
"build": "eslint src && pulp build -- --censor-lib --strict",
"test": "pulp test",
"test": "pulp test && npm run test:run:without_codePointAt",
"test:run:without_codePointAt": "node -e \"delete String.prototype.codePointAt; require('./output/Test.Main/index.js').main();\"",
"bench:build": "purs compile 'bench/**/*.purs' 'src/**/*.purs' 'bower_components/*/src/**/*.purs'",
"bench:run": "node --expose-gc -e 'require(\"./output/Bench.Main/index.js\").main()'",
"bench": "npm run bench:build && npm run bench:run"
Expand Down
10 changes: 6 additions & 4 deletions src/Data/String/CodePoints.purs
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,10 @@ unsafeCodePointAt0Fallback :: String -> CodePoint
unsafeCodePointAt0Fallback s =
let
cu0 = fromEnum (Unsafe.charAt 0 s)
cu1 = fromEnum (Unsafe.charAt 1 s)
in
if isLead cu0 && isTrail cu1
then unsurrogate cu0 cu1
else CodePoint cu0
if isLead cu0 && CU.length s > 1
then
let cu1 = fromEnum (Unsafe.charAt 1 s) in
if isTrail cu1 then unsurrogate cu0 cu1 else CodePoint cu0
else
CodePoint cu0

0 comments on commit 94c843b

Please sign in to comment.