@lblod/graph-rdfa-processor 2.1.2 → 2.1.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.
@@ -383,7 +383,7 @@ function () {
383
383
  }
384
384
 
385
385
  s += " .";
386
- return s.replaceAll("\\", "\\\\");
386
+ return s;
387
387
  }
388
388
  }, {
389
389
  key: "toObject",
@@ -544,21 +544,21 @@ function () {
544
544
  }
545
545
  }
546
546
 
547
- s += '"""' + value.replace(/"""/g, '\\"\\"\\"') + '"""^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral>';
547
+ s += '"""' + value.replace(/([^\\]|^)(\\)(?!\\)/g, "$1\\\\").replace(/"""/g, '\\"\\"\\"') + '"""^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral>';
548
548
  } else if (this.objects[i].type == "http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML") {
549
549
  // We can use innerHTML as a shortcut from the parentNode if the list is not empty
550
550
  if (this.objects[i].value.length == 0) {
551
551
  s += '""""""^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML>';
552
552
  } else {
553
- s += '"""' + this.objects[i].value[0].parentNode.innerHTML.replace(/"""/g, '\\"\\"\\"') + '"""^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML>';
553
+ s += '"""' + this.objects[i].value[0].parentNode.innerHTML.replace(/([^\\]|^)(\\)(?!\\)/g, "$1\\\\").replace(/"""/g, '\\"\\"\\"') + '"""^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML>';
554
554
  }
555
555
  } else {
556
556
  var l = this.objects[i].value.toString();
557
557
 
558
558
  if (l.indexOf("\n") >= 0 || l.indexOf("\r") >= 0) {
559
- s += '"""' + l.replace(/"""/g, '\\"\\"\\"') + '"""';
559
+ s += '"""' + l.replace(/([^\\]|^)(\\)(?!\\)/g, "$1\\\\").replace(/"/g, '\\"') + '"""';
560
560
  } else {
561
- s += '"' + l.replace(/"/g, '\\"') + '"';
561
+ s += '"' + l.replace(/([^\\]|^)(\\)(?!\\)/g, "$1\\\\").replace(/"/g, '\\"') + '"';
562
562
  }
563
563
 
564
564
  if (this.objects[i].type != "http://www.w3.org/1999/02/22-rdf-syntax-ns#PlainLiteral") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lblod/graph-rdfa-processor",
3
- "version": "2.1.2",
3
+ "version": "2.1.4",
4
4
  "description": "Green turtle GraphRdfaProcessor extracted and available as a commonJS module",
5
5
  "main": "dist/index.js",
6
6
  "module": "src/index.js",
package/src/rdfa-graph.js CHANGED
@@ -4,10 +4,10 @@ export class RDFaGraph {
4
4
  constructor() {
5
5
  var dataContext = this;
6
6
  this.curieParser = {
7
- trim: function (str) {
7
+ trim: function(str) {
8
8
  return str.replace(/^\s\s*/, "").replace(/\s\s*$/, "");
9
9
  },
10
- parse: function (value, resolve) {
10
+ parse: function(value, resolve) {
11
11
  value = this.trim(value);
12
12
  if (value.charAt(0) == "[" && value.charAt(value.length - 1) == "]") {
13
13
  value = value.substring(1, value.length - 1);
@@ -34,19 +34,19 @@ export class RDFaGraph {
34
34
  },
35
35
  };
36
36
  this.base = null;
37
- this.toString = function (requestOptions) {
37
+ this.toString = function(requestOptions) {
38
38
  var options =
39
39
  requestOptions && requestOptions.shorten
40
40
  ? { graph: this, shorten: true, prefixesUsed: {} }
41
41
  : null;
42
42
  if (requestOptions && requestOptions.blankNodePrefix) {
43
- options.filterBlankNode = function (id) {
43
+ options.filterBlankNode = function(id) {
44
44
  return "_:" + requestOptions.blankNodePrefix + id.substring(2);
45
45
  };
46
46
  }
47
47
  if (requestOptions && requestOptions.numericalBlankNodePrefix) {
48
48
  var onlyNumbers = /^[0-9]+$/;
49
- options.filterBlankNode = function (id) {
49
+ options.filterBlankNode = function(id) {
50
50
  var label = id.substring(2);
51
51
  return onlyNumbers.test(label)
52
52
  ? "_:" + requestOptions.numericalBlankNodePrefix + label
@@ -72,7 +72,7 @@ export class RDFaGraph {
72
72
  return prolog.length == 0 ? s : prolog + "\n" + s;
73
73
  };
74
74
  this.blankNodeCounter = 0;
75
- this.clear = function () {
75
+ this.clear = function() {
76
76
  this.subjects = {};
77
77
  this.prefixes = {};
78
78
  this.terms = {};
@@ -130,7 +130,7 @@ export class RDFaGraph {
130
130
  Object.defineProperty(this, "tripleCount", {
131
131
  enumerable: true,
132
132
  configurable: false,
133
- get: function () {
133
+ get: function() {
134
134
  var count = 0;
135
135
  for (var s in this.subjects) {
136
136
  var snode = this.subjects[s];
@@ -307,7 +307,7 @@ export class RDFaSubject {
307
307
  s += " " + this.predicates[predicate].toString(options);
308
308
  }
309
309
  s += " .";
310
- return s.replaceAll("\\", "\\\\");
310
+ return s;
311
311
  }
312
312
 
313
313
  toObject() {
@@ -459,7 +459,9 @@ export class RDFaPredicate {
459
459
  }
460
460
  s +=
461
461
  '"""' +
462
- value.replace(/"""/g, '\\"\\"\\"') +
462
+ value
463
+ .replace(/([^\\]|^)(\\)(?!\\)/g, "$1\\\\")
464
+ .replace(/"""/g, '\\"\\"\\"') +
463
465
  '"""^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral>';
464
466
  } else if (
465
467
  this.objects[i].type ==
@@ -471,18 +473,24 @@ export class RDFaPredicate {
471
473
  } else {
472
474
  s +=
473
475
  '"""' +
474
- this.objects[i].value[0].parentNode.innerHTML.replace(
475
- /"""/g,
476
- '\\"\\"\\"',
477
- ) +
476
+ this.objects[i].value[0].parentNode.innerHTML
477
+ .replace(/([^\\]|^)(\\)(?!\\)/g, "$1\\\\")
478
+ .replace(/"""/g, '\\"\\"\\"') +
478
479
  '"""^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML>';
479
480
  }
480
481
  } else {
481
482
  var l = this.objects[i].value.toString();
483
+
482
484
  if (l.indexOf("\n") >= 0 || l.indexOf("\r") >= 0) {
483
- s += '"""' + l.replace(/"""/g, '\\"\\"\\"') + '"""';
485
+ s +=
486
+ '"""' +
487
+ l.replace(/([^\\]|^)(\\)(?!\\)/g, "$1\\\\").replace(/"/g, '\\"') +
488
+ '"""';
484
489
  } else {
485
- s += '"' + l.replace(/"/g, '\\"') + '"';
490
+ s +=
491
+ '"' +
492
+ l.replace(/([^\\]|^)(\\)(?!\\)/g, "$1\\\\").replace(/"/g, '\\"') +
493
+ '"';
486
494
  }
487
495
  if (
488
496
  this.objects[i].type !=
@@ -498,7 +506,7 @@ export class RDFaPredicate {
498
506
  }
499
507
  }
500
508
 
501
- RDFaPredicate.getPrefixMap = function (e) {
509
+ RDFaPredicate.getPrefixMap = function(e) {
502
510
  var prefixMap = {};
503
511
  while (e.attributes) {
504
512
  for (var i = 0; i < e.attributes.length; i++) {
package/test/test.js CHANGED
@@ -2,7 +2,7 @@ import { jsdom } from "jsdom";
2
2
  import assert from "assert";
3
3
  import getRDFaGraph from "../src";
4
4
  import { readFileSync, writeFileSync } from "fs";
5
- describe("getRDFaGraph", function () {
5
+ describe("getRDFaGraph", function() {
6
6
  let html = `<div typeof="rdfs:Class" resource="http://schema.org/CreativeWork">
7
7
  <span class="h" property="rdfs:label">CreativeWork</span>
8
8
  <span property="rdfs:comment">The most generic kind of creative work, including books, movies, photographs, software programs, etc.</span>
@@ -17,14 +17,14 @@ describe("getRDFaGraph", function () {
17
17
  <http://purl.org/dc/terms/source> <http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_rNews> .
18
18
  `;
19
19
 
20
- it("should getRDFaGraph from a document", function () {
20
+ it("should getRDFaGraph from a document", function() {
21
21
  let { document } = jsdom(html).defaultView.window;
22
22
  let graph = getRDFaGraph(document, { baseURI: "http://localhost" });
23
23
  assert.equal(graph.toString(), expected);
24
24
  });
25
25
 
26
- it.only("whatever", () => {
27
- let ht = readFileSync("./bug2.html");
26
+ it("whatever", () => {
27
+ let ht = readFileSync("./bug4.html");
28
28
  let { document } = jsdom(ht).defaultView.window;
29
29
 
30
30
  let graph = getRDFaGraph(document, {
@@ -40,7 +40,7 @@ describe("getRDFaGraph", function () {
40
40
  writeFileSync("/tmp/x.ttl", graph.toString(), "utf8");
41
41
  });
42
42
 
43
- it("should getRDFaGraph from a node", function () {
43
+ it("should getRDFaGraph from a node", function() {
44
44
  let { document } = jsdom(html).defaultView.window;
45
45
  let graph = getRDFaGraph(document.getElementsByTagName("div")[0], {
46
46
  baseURI: "http://localhost",