n3 2.0.1 → 2.0.3

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.
@@ -106,10 +106,11 @@ class Literal extends Term {
106
106
 
107
107
  // ### The direction of this literal
108
108
  get direction() {
109
- // Find the last double dash (e.g., '"abc"@en-us--ltr')
109
+ // Find the last double dash after the closing quote (e.g., '"abc"@en-us--ltr')
110
110
  const id = this.id;
111
- const atPos = id.lastIndexOf('--') + 2;
112
- return atPos > 1 && atPos < id.length ? id.substr(atPos).toLowerCase() : '';
111
+ const endPos = id.lastIndexOf('"');
112
+ const dirPos = id.lastIndexOf('--');
113
+ return dirPos > endPos && dirPos + 2 < id.length ? id.substr(dirPos + 2).toLowerCase() : '';
113
114
  }
114
115
 
115
116
  // ### The datatype IRI of this literal
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 of length larger than 8', token);
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.1",
3
+ "version": "2.0.3",
4
4
  "description": "Lightning fast, asynchronous, streaming Turtle / N3 / RDF library.",
5
5
  "author": "Ruben Verborgh <ruben.verborgh@gmail.com>",
6
6
  "keywords": [
@@ -95,10 +95,11 @@ export class Literal extends Term {
95
95
 
96
96
  // ### The direction of this literal
97
97
  get direction() {
98
- // Find the last double dash (e.g., '"abc"@en-us--ltr')
98
+ // Find the last double dash after the closing quote (e.g., '"abc"@en-us--ltr')
99
99
  const id = this.id;
100
- const atPos = id.lastIndexOf('--') + 2;
101
- return atPos > 1 && atPos < id.length ? id.substr(atPos).toLowerCase() : '';
100
+ const endPos = id.lastIndexOf('"');
101
+ const dirPos = id.lastIndexOf('--');
102
+ return dirPos > endPos && dirPos + 2 < id.length ? id.substr(dirPos + 2).toLowerCase() : '';
102
103
  }
103
104
 
104
105
  // ### The datatype IRI of this literal
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 of length larger than 8', token);
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;