n3 2.0.3 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/N3Lexer.js CHANGED
@@ -45,6 +45,9 @@ const escapeReplacements = {
45
45
  '%': '%'
46
46
  };
47
47
  const illegalIriChars = /[\x00-\x20<>\\"\{\}\|\^\`]/;
48
+ function isSurrogateCodePoint(charCode) {
49
+ return charCode >= 0xD800 && charCode <= 0xDFFF;
50
+ }
48
51
  const lineModeRegExps = {
49
52
  _iri: true,
50
53
  _unescapedIri: true,
@@ -414,10 +417,21 @@ class N3Lexer {
414
417
  let invalid = false;
415
418
  const replaced = item.replace(escapeSequence, (sequence, unicode4, unicode8, escapedChar) => {
416
419
  // 4-digit unicode character
417
- if (typeof unicode4 === 'string') return String.fromCharCode(Number.parseInt(unicode4, 16));
420
+ if (typeof unicode4 === 'string') {
421
+ const charCode = Number.parseInt(unicode4, 16);
422
+ if (isSurrogateCodePoint(charCode)) {
423
+ invalid = true;
424
+ return '';
425
+ }
426
+ return String.fromCharCode(charCode);
427
+ }
418
428
  // 8-digit unicode character
419
429
  if (typeof unicode8 === 'string') {
420
430
  let charCode = Number.parseInt(unicode8, 16);
431
+ if (isSurrogateCodePoint(charCode)) {
432
+ invalid = true;
433
+ return '';
434
+ }
421
435
  return charCode <= 0xFFFF ? String.fromCharCode(Number.parseInt(unicode8, 16)) : String.fromCharCode(0xD800 + ((charCode -= 0x10000) >> 10), 0xDC00 + (charCode & 0x3FF));
422
436
  }
423
437
  // fixed escape sequence
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n3",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "description": "Lightning fast, asynchronous, streaming Turtle / N3 / RDF library.",
5
5
  "author": "Ruben Verborgh <ruben.verborgh@gmail.com>",
6
6
  "keywords": [
@@ -39,11 +39,11 @@
39
39
  "docco": "^0.9.1",
40
40
  "eslint": "^8.57.1",
41
41
  "eslint-plugin-import": "^2.29.1",
42
- "eslint-plugin-jest": "^28.8.3",
42
+ "eslint-plugin-jest": "^29.15.0",
43
43
  "jest": "^29.7.0",
44
- "pre-commit": "^1.2.2",
44
+ "pre-commit": "^2.0.0",
45
45
  "rdf-isomorphic": "^2.0.0",
46
- "rdf-test-suite": "^1.25.0",
46
+ "rdf-test-suite": "^2.1.4",
47
47
  "streamify-string": "^1.0.1",
48
48
  "uglify-js": "^3.14.3"
49
49
  },
package/src/N3Lexer.js CHANGED
@@ -15,6 +15,10 @@ const escapeReplacements = {
15
15
  };
16
16
  const illegalIriChars = /[\x00-\x20<>\\"\{\}\|\^\`]/;
17
17
 
18
+ function isSurrogateCodePoint(charCode) {
19
+ return charCode >= 0xD800 && charCode <= 0xDFFF;
20
+ }
21
+
18
22
  const lineModeRegExps = {
19
23
  _iri: true,
20
24
  _unescapedIri: true,
@@ -419,11 +423,21 @@ export default class N3Lexer {
419
423
  let invalid = false;
420
424
  const replaced = item.replace(escapeSequence, (sequence, unicode4, unicode8, escapedChar) => {
421
425
  // 4-digit unicode character
422
- if (typeof unicode4 === 'string')
423
- return String.fromCharCode(Number.parseInt(unicode4, 16));
426
+ if (typeof unicode4 === 'string') {
427
+ const charCode = Number.parseInt(unicode4, 16);
428
+ if (isSurrogateCodePoint(charCode)) {
429
+ invalid = true;
430
+ return '';
431
+ }
432
+ return String.fromCharCode(charCode);
433
+ }
424
434
  // 8-digit unicode character
425
435
  if (typeof unicode8 === 'string') {
426
436
  let charCode = Number.parseInt(unicode8, 16);
437
+ if (isSurrogateCodePoint(charCode)) {
438
+ invalid = true;
439
+ return '';
440
+ }
427
441
  return charCode <= 0xFFFF ? String.fromCharCode(Number.parseInt(unicode8, 16)) :
428
442
  String.fromCharCode(0xD800 + ((charCode -= 0x10000) >> 10), 0xDC00 + (charCode & 0x3FF));
429
443
  }