n3 2.0.2 → 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/browser/n3.min.js +1 -1
- package/lib/N3Lexer.js +15 -1
- package/lib/N3Parser.js +1 -1
- package/package.json +4 -4
- package/src/N3Lexer.js +16 -2
- package/src/N3Parser.js +2 -2
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')
|
|
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/lib/N3Parser.js
CHANGED
|
@@ -549,7 +549,7 @@ class N3Parser {
|
|
|
549
549
|
break;
|
|
550
550
|
// Create a language-tagged string
|
|
551
551
|
case 'langcode':
|
|
552
|
-
if (token.value.length > 8) return this._error('Detected language tag
|
|
552
|
+
if (token.value.split('-').some(t => t.length > 8)) return this._error('Detected language tag with subtag longer than 8 characters', token);
|
|
553
553
|
literal = this._factory.literal(this._literalValue, token.value);
|
|
554
554
|
this._literalLanguage = token.value;
|
|
555
555
|
token = null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "n3",
|
|
3
|
-
"version": "2.0.
|
|
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": "^
|
|
42
|
+
"eslint-plugin-jest": "^29.15.0",
|
|
43
43
|
"jest": "^29.7.0",
|
|
44
|
-
"pre-commit": "^
|
|
44
|
+
"pre-commit": "^2.0.0",
|
|
45
45
|
"rdf-isomorphic": "^2.0.0",
|
|
46
|
-
"rdf-test-suite": "^1.
|
|
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
|
-
|
|
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
|
}
|
package/src/N3Parser.js
CHANGED
|
@@ -585,8 +585,8 @@ export default class N3Parser {
|
|
|
585
585
|
break;
|
|
586
586
|
// Create a language-tagged string
|
|
587
587
|
case 'langcode':
|
|
588
|
-
if (token.value.length > 8)
|
|
589
|
-
return this._error('Detected language tag
|
|
588
|
+
if (token.value.split('-').some(t => t.length > 8))
|
|
589
|
+
return this._error('Detected language tag with subtag longer than 8 characters', token);
|
|
590
590
|
literal = this._factory.literal(this._literalValue, token.value);
|
|
591
591
|
this._literalLanguage = token.value;
|
|
592
592
|
token = null;
|