diff --git a/package.json b/package.json index d44d01e..28a3fd3 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/src/Data/String/CodePoints.purs b/src/Data/String/CodePoints.purs index 7f72b7b..8492087 100644 --- a/src/Data/String/CodePoints.purs +++ b/src/Data/String/CodePoints.purs @@ -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