@lblod/graph-rdfa-processor 2.1.4 → 2.1.6

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.
@@ -397,6 +397,10 @@ function (_URIResolver) {
397
397
  baseURI = options.baseURIMap(baseURI);
398
398
  }
399
399
 
400
+ if (baseURI == "about:blank") {
401
+ baseURI = options.baseURI;
402
+ }
403
+
400
404
  return baseURI;
401
405
  };
402
406
 
@@ -21,6 +21,8 @@ function () {
21
21
  _createClass(URIResolver, [{
22
22
  key: "parseURI",
23
23
  value: function parseURI(uri) {
24
+ uri = uri.replace("\n", ""); // bugfix: sometimes there is a \n in the uri...
25
+
24
26
  var match = URIResolver.SCHEME.exec(uri);
25
27
 
26
28
  if (!match) {
@@ -33,7 +35,7 @@ function () {
33
35
  parsed.scheme = match[0].substring(0, match[0].length - 1);
34
36
  parsed.schemeSpecificPart = parsed.spec.substring(match[0].length);
35
37
 
36
- if (parsed.schemeSpecificPart.charAt(0) == '/' && parsed.schemeSpecificPart.charAt(1) == '/') {
38
+ if (parsed.schemeSpecificPart.charAt(0) == "/" && parsed.schemeSpecificPart.charAt(1) == "/") {
37
39
  this.parseGeneric(parsed);
38
40
  } else {
39
41
  parsed.isGeneric = false;
@@ -103,8 +105,8 @@ function () {
103
105
  return this.spec;
104
106
  }
105
107
 
106
- if (href.charAt(0) == '#') {
107
- var lastHash = this.spec.lastIndexOf('#');
108
+ if (href.charAt(0) == "#") {
109
+ var lastHash = this.spec.lastIndexOf("#");
108
110
  return lastHash < 0 ? this.spec + href : this.spec.substring(0, lastHash) + href;
109
111
  }
110
112
 
@@ -112,15 +114,15 @@ function () {
112
114
  throw new Error("Cannot resolve uri against non-generic URI: " + this.spec);
113
115
  }
114
116
 
115
- var colon = href.indexOf(':');
117
+ var colon = href.indexOf(":");
116
118
 
117
- if (href.charAt(0) == '/') {
119
+ if (href.charAt(0) == "/") {
118
120
  return this.scheme + "://" + this.authority + href;
119
- } else if (href.charAt(0) == '.' && href.charAt(1) == '/') {
120
- if (this.path.charAt(this.path.length - 1) == '/') {
121
+ } else if (href.charAt(0) == "." && href.charAt(1) == "/") {
122
+ if (this.path.charAt(this.path.length - 1) == "/") {
121
123
  return this.scheme + "://" + this.authority + this.path + href.substring(2);
122
124
  } else {
123
- var last = this.path.lastIndexOf('/');
125
+ var last = this.path.lastIndexOf("/");
124
126
  return this.scheme + "://" + this.authority + this.path.substring(0, last) + href.substring(1);
125
127
  }
126
128
  } else if (URIResolver.SCHEME.test(href)) {
@@ -128,10 +130,10 @@ function () {
128
130
  } else if (href.charAt(0) == "?") {
129
131
  return this.scheme + "://" + this.authority + this.path + href;
130
132
  } else {
131
- if (this.path.charAt(this.path.length - 1) == '/') {
133
+ if (this.path.charAt(this.path.length - 1) == "/") {
132
134
  return this.scheme + "://" + this.authority + this.path + href;
133
135
  } else {
134
- var last = this.path.lastIndexOf('/');
136
+ var last = this.path.lastIndexOf("/");
135
137
  return this.scheme + "://" + this.authority + this.path.substring(0, last + 1) + href;
136
138
  }
137
139
  }
@@ -159,7 +161,7 @@ function () {
159
161
  for (; i < this.segments.length && i < otherURI.segments.length; i++) {
160
162
  if (this.segments[i] != otherURI.segments[i]) {
161
163
  //alert(this.path+" different from "+otherURI.path+" at '"+this.segments[i]+"' vs '"+otherURI.segments[i]+"'");
162
- var offset = otherURI.path.charAt(otherURI.path.length - 1) == '/' ? 0 : -1;
164
+ var offset = otherURI.path.charAt(otherURI.path.length - 1) == "/" ? 0 : -1;
163
165
  var relative = "";
164
166
 
165
167
  for (var j = i; j < otherURI.segments.length + offset; j++) {
@@ -174,7 +176,7 @@ function () {
174
176
  }
175
177
  }
176
178
 
177
- if (this.path.charAt(this.path.length - 1) == '/') {
179
+ if (this.path.charAt(this.path.length - 1) == "/") {
178
180
  relative += "/";
179
181
  }
180
182
 
@@ -195,7 +197,7 @@ function () {
195
197
  }
196
198
  }
197
199
 
198
- if (this.path.charAt(this.path.length - 1) == '/') {
200
+ if (this.path.charAt(this.path.length - 1) == "/") {
199
201
  relative += "/";
200
202
  }
201
203
 
@@ -210,7 +212,7 @@ function () {
210
212
  }, {
211
213
  key: "parseGeneric",
212
214
  value: function parseGeneric(parsed) {
213
- if (parsed.schemeSpecificPart.charAt(0) != '/' || parsed.schemeSpecificPart.charAt(1) != '/') {
215
+ if (parsed.schemeSpecificPart.charAt(0) != "/" || parsed.schemeSpecificPart.charAt(1) != "/") {
214
216
  throw new Error("Generic URI values should start with '//':" + parsed.spec);
215
217
  }
216
218
 
@@ -218,14 +220,14 @@ function () {
218
220
  var pathStart = work.indexOf("/");
219
221
  parsed.authority = pathStart < 0 ? work : work.substring(0, pathStart);
220
222
  parsed.path = pathStart < 0 ? "" : work.substring(pathStart);
221
- var hash = parsed.path.indexOf('#');
223
+ var hash = parsed.path.indexOf("#");
222
224
 
223
225
  if (hash >= 0) {
224
226
  parsed.fragment = parsed.path.substring(hash + 1);
225
227
  parsed.path = parsed.path.substring(0, hash);
226
228
  }
227
229
 
228
- var questionMark = parsed.path.indexOf('?');
230
+ var questionMark = parsed.path.indexOf("?");
229
231
 
230
232
  if (questionMark >= 0) {
231
233
  parsed.query = parsed.path.substring(questionMark + 1);
@@ -237,15 +239,15 @@ function () {
237
239
  } else {
238
240
  parsed.segments = parsed.path.split(/\//);
239
241
 
240
- if (parsed.segments.length > 0 && parsed.segments[0] == '' && parsed.path.length > 1 && parsed.path.charAt(1) != '/') {
242
+ if (parsed.segments.length > 0 && parsed.segments[0] == "" && parsed.path.length > 1 && parsed.path.charAt(1) != "/") {
241
243
  // empty segment at the start, remove it
242
244
  parsed.segments.shift();
243
245
  }
244
246
 
245
- if (parsed.segments.length > 0 && parsed.path.length > 0 && parsed.path.charAt(parsed.path.length - 1) == '/' && parsed.segments[parsed.segments.length - 1] == '') {
247
+ if (parsed.segments.length > 0 && parsed.path.length > 0 && parsed.path.charAt(parsed.path.length - 1) == "/" && parsed.segments[parsed.segments.length - 1] == "") {
246
248
  // we may have an empty the end
247
249
  // check to see if it is legimate
248
- if (parsed.path.length > 1 && parsed.path.charAt(parsed.path.length - 2) != '/') {
250
+ if (parsed.path.length > 1 && parsed.path.charAt(parsed.path.length - 2) != "/") {
249
251
  parsed.segments.pop();
250
252
  }
251
253
  } // check for non-escaped characters
@@ -256,7 +258,7 @@ function () {
256
258
 
257
259
  for (var j = 0; j < check.length; j++) {
258
260
  if (check[j].length > 0) {
259
- throw new Error("Unecaped character " + check[j].charAt(0) + " (" + check[j].charCodeAt(0) + ") in URI " + parsed.spec);
261
+ throw new Error("Unescaped character " + check[j].charAt(0) + " (" + check[j].charCodeAt(0) + ") in URI " + parsed.spec);
260
262
  }
261
263
  }
262
264
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lblod/graph-rdfa-processor",
3
- "version": "2.1.4",
3
+ "version": "2.1.6",
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",
@@ -208,9 +208,9 @@ export default class RDFaProcessor extends URIResolver {
208
208
  if (node.ownerDocument.doctype) {
209
209
  if (
210
210
  node.ownerDocument.doctype.publicId ==
211
- "-//W3C//DTD XHTML+RDFa 1.0//EN" &&
211
+ "-//W3C//DTD XHTML+RDFa 1.0//EN" &&
212
212
  node.ownerDocument.doctype.systemId ==
213
- "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"
213
+ "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"
214
214
  ) {
215
215
  console.log(
216
216
  "WARNING: RDF 1.0 is not supported. Defaulting to HTML5 mode.",
@@ -218,9 +218,9 @@ export default class RDFaProcessor extends URIResolver {
218
218
  this.setHTMLContext();
219
219
  } else if (
220
220
  node.ownerDocument.doctype.publicId ==
221
- "-//W3C//DTD XHTML+RDFa 1.1//EN" &&
221
+ "-//W3C//DTD XHTML+RDFa 1.1//EN" &&
222
222
  node.ownerDocument.doctype.systemId ==
223
- "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd"
223
+ "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd"
224
224
  ) {
225
225
  this.setXHTMLContext();
226
226
  } else {
@@ -329,11 +329,11 @@ export default class RDFaProcessor extends URIResolver {
329
329
  "http://www.w3.org/1999/xhtml/vocab#transformation";
330
330
  }
331
331
 
332
- init() {}
332
+ init() { }
333
333
 
334
- newSubjectOrigin(origin, subject) {}
334
+ newSubjectOrigin(origin, subject) { }
335
335
 
336
- addTriple(origin, subject, predicate, object) {}
336
+ addTriple(origin, subject, predicate, object) { }
337
337
 
338
338
  process(node, options) {
339
339
  if (node.nodeType == Node.DOCUMENT_NODE) {
@@ -344,7 +344,7 @@ export default class RDFaProcessor extends URIResolver {
344
344
  }
345
345
  var queue = [];
346
346
  // Fix for Firefox that includes the hash in the base URI
347
- var removeHash = function (baseURI) {
347
+ var removeHash = function(baseURI) {
348
348
  var hash = baseURI.indexOf("#");
349
349
  if (hash >= 0) {
350
350
  baseURI = baseURI.substring(0, hash);
@@ -352,6 +352,9 @@ export default class RDFaProcessor extends URIResolver {
352
352
  if (options && options.baseURIMap) {
353
353
  baseURI = options.baseURIMap(baseURI);
354
354
  }
355
+ if (baseURI == "about:blank") {
356
+ baseURI = options.baseURI;
357
+ }
355
358
  return baseURI;
356
359
  };
357
360
  queue.push({
@@ -864,18 +867,18 @@ export default class RDFaProcessor extends URIResolver {
864
867
  datatypeAtt.value == ""
865
868
  ? RDFaProcessor.PlainLiteralURI
866
869
  : this.parseTermOrCURIEOrAbsURI(
867
- datatypeAtt.value,
868
- vocabulary,
869
- context.terms,
870
- prefixes,
871
- base,
872
- );
870
+ datatypeAtt.value,
871
+ vocabulary,
872
+ context.terms,
873
+ prefixes,
874
+ base,
875
+ );
873
876
  if (datetimeAtt && !contentAtt) {
874
877
  content = datetimeAtt.value;
875
878
  } else {
876
879
  content =
877
880
  datatype == RDFaProcessor.XMLLiteralURI ||
878
- datatype == RDFaProcessor.HTMLLiteralURI
881
+ datatype == RDFaProcessor.HTMLLiteralURI
879
882
  ? null
880
883
  : contentAtt
881
884
  ? contentAtt.value
@@ -943,10 +946,10 @@ export default class RDFaProcessor extends URIResolver {
943
946
  datatype == RDFaProcessor.HTMLLiteralURI
944
947
  ? { type: datatype, value: current.childNodes }
945
948
  : {
946
- type: datatype ? datatype : RDFaProcessor.PlainLiteralURI,
947
- value: content,
948
- language: language,
949
- },
949
+ type: datatype ? datatype : RDFaProcessor.PlainLiteralURI,
950
+ value: content,
951
+ language: language,
952
+ },
950
953
  );
951
954
  } else {
952
955
  if (
@@ -1073,7 +1076,7 @@ export default class RDFaProcessor extends URIResolver {
1073
1076
  }
1074
1077
  }
1075
1078
 
1076
- copyProperties() {}
1079
+ copyProperties() { }
1077
1080
 
1078
1081
  push(parent, subject) {
1079
1082
  return {
@@ -1108,7 +1111,7 @@ RDFaProcessor.NCNAME = new RegExp(
1108
1111
  "^" + RDFaProcessor.nameStartChar + RDFaProcessor.nameChar + "*$",
1109
1112
  );
1110
1113
 
1111
- RDFaProcessor.trim = function (str) {
1114
+ RDFaProcessor.trim = function(str) {
1112
1115
  return str.replace(/^\s\s*/, "").replace(/\s\s*$/, "");
1113
1116
  };
1114
1117
 
@@ -1144,7 +1147,7 @@ RDFaProcessor.dateTimeTypes = [
1144
1147
  },
1145
1148
  ];
1146
1149
 
1147
- RDFaProcessor.deriveDateTimeType = function (value) {
1150
+ RDFaProcessor.deriveDateTimeType = function(value) {
1148
1151
  for (var i = 0; i < RDFaProcessor.dateTimeTypes.length; i++) {
1149
1152
  //console.log("Checking "+value+" against "+RDFaProcessor.dateTimeTypes[i].type);
1150
1153
  var matched = RDFaProcessor.dateTimeTypes[i].pattern.exec(value);
@@ -1,14 +1,17 @@
1
1
  export default class URIResolver {
2
-
3
2
  parseURI(uri) {
3
+ uri = uri.replace("\n", ""); // bugfix: sometimes there is a \n in the uri...
4
4
  var match = URIResolver.SCHEME.exec(uri);
5
5
  if (!match) {
6
6
  throw new Error("Bad URI value, no scheme: " + uri);
7
7
  }
8
8
  var parsed = { spec: uri };
9
- parsed.scheme = match[0].substring(0,match[0].length-1);
9
+ parsed.scheme = match[0].substring(0, match[0].length - 1);
10
10
  parsed.schemeSpecificPart = parsed.spec.substring(match[0].length);
11
- if (parsed.schemeSpecificPart.charAt(0)=='/' && parsed.schemeSpecificPart.charAt(1)=='/') {
11
+ if (
12
+ parsed.schemeSpecificPart.charAt(0) == "/" &&
13
+ parsed.schemeSpecificPart.charAt(1) == "/"
14
+ ) {
12
15
  this.parseGeneric(parsed);
13
16
  } else {
14
17
  parsed.isGeneric = false;
@@ -17,38 +20,42 @@ export default class URIResolver {
17
20
  if (!this.isGeneric) {
18
21
  return;
19
22
  }
20
- if (this.segments.length==0) {
23
+ if (this.segments.length == 0) {
21
24
  return;
22
25
  }
23
26
  // edge case of ending in "/."
24
- if (this.path.length>1 && this.path.substring(this.path.length-2)=="/.") {
25
- this.path = this.path.substring(0,this.path.length-1);
26
- this.segments.splice(this.segments.length-1,1);
27
- this.schemeSpecificPart = "//"+this.authority+this.path;
27
+ if (
28
+ this.path.length > 1 &&
29
+ this.path.substring(this.path.length - 2) == "/."
30
+ ) {
31
+ this.path = this.path.substring(0, this.path.length - 1);
32
+ this.segments.splice(this.segments.length - 1, 1);
33
+ this.schemeSpecificPart = "//" + this.authority + this.path;
28
34
  if (typeof this.query != "undefined") {
29
35
  this.schemeSpecificPart += "?" + this.query;
30
36
  }
31
37
  if (typeof this.fragment != "undefined") {
32
38
  this.schemeSpecificPart += "#" + this.fragment;
33
39
  }
34
- this.spec = this.scheme+":"+this.schemeSpecificPart;
40
+ this.spec = this.scheme + ":" + this.schemeSpecificPart;
35
41
  return;
36
42
  }
37
- var end = this.path.charAt(this.path.length-1);
38
- if (end!="/") {
43
+ var end = this.path.charAt(this.path.length - 1);
44
+ if (end != "/") {
39
45
  end = "";
40
46
  }
41
- for (var i=0; i < this.segments.length; i++) {
42
- if (i>0 && this.segments[i]=="..") {
43
- this.segments.splice(i-1,2);
47
+ for (var i = 0; i < this.segments.length; i++) {
48
+ if (i > 0 && this.segments[i] == "..") {
49
+ this.segments.splice(i - 1, 2);
44
50
  i -= 2;
45
51
  }
46
- if (this.segments[i]==".") {
47
- this.segments.splice(i,1);
52
+ if (this.segments[i] == ".") {
53
+ this.segments.splice(i, 1);
48
54
  i--;
49
55
  }
50
56
  }
51
- this.path = this.segments.length==0 ? "/" : "/" + this.segments.join("/") + end;
57
+ this.path =
58
+ this.segments.length == 0 ? "/" : "/" + this.segments.join("/") + end;
52
59
  this.schemeSpecificPart = "//" + this.authority + this.path;
53
60
  if (typeof this.query != "undefined") {
54
61
  this.schemeSpecificPart += "?" + this.query;
@@ -56,148 +63,202 @@ export default class URIResolver {
56
63
  if (typeof this.fragment != "undefined") {
57
64
  this.schemeSpecificPart += "#" + this.fragment;
58
65
  }
59
- this.spec = this.scheme+":"+this.schemeSpecificPart;
60
- }
66
+ this.spec = this.scheme + ":" + this.schemeSpecificPart;
67
+ };
61
68
 
62
69
  parsed.resolve = function(href) {
63
70
  if (!href) {
64
71
  return this.spec;
65
72
  }
66
- if (href.charAt(0)=='#') {
67
- var lastHash = this.spec.lastIndexOf('#');
68
- return lastHash<0 ? this.spec+href : this.spec.substring(0,lastHash)+href;
73
+ if (href.charAt(0) == "#") {
74
+ var lastHash = this.spec.lastIndexOf("#");
75
+ return lastHash < 0
76
+ ? this.spec + href
77
+ : this.spec.substring(0, lastHash) + href;
69
78
  }
70
79
  if (!this.isGeneric) {
71
- throw new Error("Cannot resolve uri against non-generic URI: " + this.spec);
72
- }
73
- var colon = href.indexOf(':');
74
- if (href.charAt(0)=='/') {
75
- return this.scheme+"://"+this.authority+href;
76
- } else if (href.charAt(0)=='.' && href.charAt(1)=='/') {
77
- if (this.path.charAt(this.path.length-1)=='/') {
78
- return this.scheme+"://"+this.authority+this.path+href.substring(2);
80
+ throw new Error(
81
+ "Cannot resolve uri against non-generic URI: " + this.spec,
82
+ );
83
+ }
84
+ var colon = href.indexOf(":");
85
+ if (href.charAt(0) == "/") {
86
+ return this.scheme + "://" + this.authority + href;
87
+ } else if (href.charAt(0) == "." && href.charAt(1) == "/") {
88
+ if (this.path.charAt(this.path.length - 1) == "/") {
89
+ return (
90
+ this.scheme + "://" + this.authority + this.path + href.substring(2)
91
+ );
79
92
  } else {
80
- var last = this.path.lastIndexOf('/');
81
- return this.scheme+"://"+this.authority+this.path.substring(0,last)+href.substring(1);
93
+ var last = this.path.lastIndexOf("/");
94
+ return (
95
+ this.scheme +
96
+ "://" +
97
+ this.authority +
98
+ this.path.substring(0, last) +
99
+ href.substring(1)
100
+ );
82
101
  }
83
102
  } else if (URIResolver.SCHEME.test(href)) {
84
103
  return href;
85
- } else if (href.charAt(0)=="?") {
86
- return this.scheme+"://"+this.authority+this.path+href;
104
+ } else if (href.charAt(0) == "?") {
105
+ return this.scheme + "://" + this.authority + this.path + href;
87
106
  } else {
88
- if (this.path.charAt(this.path.length-1)=='/') {
89
- return this.scheme+"://"+this.authority+this.path+href;
107
+ if (this.path.charAt(this.path.length - 1) == "/") {
108
+ return this.scheme + "://" + this.authority + this.path + href;
90
109
  } else {
91
- var last = this.path.lastIndexOf('/');
92
- return this.scheme+"://"+this.authority+this.path.substring(0,last+1)+href;
110
+ var last = this.path.lastIndexOf("/");
111
+ return (
112
+ this.scheme +
113
+ "://" +
114
+ this.authority +
115
+ this.path.substring(0, last + 1) +
116
+ href
117
+ );
93
118
  }
94
119
  }
95
120
  };
96
121
 
97
122
  parsed.relativeTo = function(otherURI) {
98
- if (otherURI.scheme!=this.scheme) {
123
+ if (otherURI.scheme != this.scheme) {
99
124
  return this.spec;
100
125
  }
101
126
  if (!this.isGeneric) {
102
- throw new Error("A non generic URI cannot be made relative: " + this.spec);
127
+ throw new Error(
128
+ "A non generic URI cannot be made relative: " + this.spec,
129
+ );
103
130
  }
104
131
  if (!otherURI.isGeneric) {
105
- throw new Error("Cannot make a relative URI against a non-generic URI: " + otherURI.spec);
132
+ throw new Error(
133
+ "Cannot make a relative URI against a non-generic URI: " +
134
+ otherURI.spec,
135
+ );
106
136
  }
107
- if (otherURI.authority!=this.authority) {
137
+ if (otherURI.authority != this.authority) {
108
138
  return this.spec;
109
139
  }
110
- var i=0;
140
+ var i = 0;
111
141
  for (; i < this.segments.length && i < otherURI.segments.length; i++) {
112
- if (this.segments[i]!=otherURI.segments[i]) {
142
+ if (this.segments[i] != otherURI.segments[i]) {
113
143
  //alert(this.path+" different from "+otherURI.path+" at '"+this.segments[i]+"' vs '"+otherURI.segments[i]+"'");
114
- var offset = otherURI.path.charAt(otherURI.path.length-1)=='/' ? 0 : -1;
144
+ var offset =
145
+ otherURI.path.charAt(otherURI.path.length - 1) == "/" ? 0 : -1;
115
146
  var relative = "";
116
- for (var j=i; j < otherURI.segments.length+offset; j++) {
147
+ for (var j = i; j < otherURI.segments.length + offset; j++) {
117
148
  relative += "../";
118
149
  }
119
- for (var j=i; j < this.segments.length; j++) {
150
+ for (var j = i; j < this.segments.length; j++) {
120
151
  relative += this.segments[j];
121
- if ((j+1) < this.segments.length) {
152
+ if (j + 1 < this.segments.length) {
122
153
  relative += "/";
123
154
  }
124
155
  }
125
- if (this.path.charAt(this.path.length-1)=='/') {
156
+ if (this.path.charAt(this.path.length - 1) == "/") {
126
157
  relative += "/";
127
158
  }
128
159
  return relative;
129
160
  }
130
161
  }
131
- if (this.segments.length==otherURI.segments.length) {
132
- return this.hash ? this.hash : (this.query ? this.query : "");
162
+ if (this.segments.length == otherURI.segments.length) {
163
+ return this.hash ? this.hash : this.query ? this.query : "";
133
164
  } else if (i < this.segments.length) {
134
165
  var relative = "";
135
- for (var j=i; j < this.segments.length; j++) {
166
+ for (var j = i; j < this.segments.length; j++) {
136
167
  relative += this.segments[j];
137
- if ((j+1) < this.segments.length) {
168
+ if (j + 1 < this.segments.length) {
138
169
  relative += "/";
139
170
  }
140
171
  }
141
- if (this.path.charAt(this.path.length-1)=='/') {
172
+ if (this.path.charAt(this.path.length - 1) == "/") {
142
173
  relative += "/";
143
174
  }
144
175
  return relative;
145
176
  } else {
146
- throw new Error("Cannot calculate a relative URI for "+this.spec+" against " + otherURI.spec);
177
+ throw new Error(
178
+ "Cannot calculate a relative URI for " +
179
+ this.spec +
180
+ " against " +
181
+ otherURI.spec,
182
+ );
147
183
  }
148
184
  };
149
185
  return parsed;
150
186
  }
151
187
 
152
188
  parseGeneric(parsed) {
153
- if (parsed.schemeSpecificPart.charAt(0)!='/' || parsed.schemeSpecificPart.charAt(1)!='/') {
154
- throw new Error("Generic URI values should start with '//':" + parsed.spec);
189
+ if (
190
+ parsed.schemeSpecificPart.charAt(0) != "/" ||
191
+ parsed.schemeSpecificPart.charAt(1) != "/"
192
+ ) {
193
+ throw new Error(
194
+ "Generic URI values should start with '//':" + parsed.spec,
195
+ );
155
196
  }
156
197
 
157
198
  var work = parsed.schemeSpecificPart.substring(2);
158
199
  var pathStart = work.indexOf("/");
159
- parsed.authority = pathStart<0 ? work : work.substring(0,pathStart);
160
- parsed.path = pathStart<0 ? "" : work.substring(pathStart);
161
- var hash = parsed.path.indexOf('#');
162
- if (hash>=0) {
163
- parsed.fragment = parsed.path.substring(hash+1);
164
- parsed.path = parsed.path.substring(0,hash);
200
+ parsed.authority = pathStart < 0 ? work : work.substring(0, pathStart);
201
+ parsed.path = pathStart < 0 ? "" : work.substring(pathStart);
202
+ var hash = parsed.path.indexOf("#");
203
+ if (hash >= 0) {
204
+ parsed.fragment = parsed.path.substring(hash + 1);
205
+ parsed.path = parsed.path.substring(0, hash);
165
206
  }
166
- var questionMark = parsed.path.indexOf('?');
167
- if (questionMark>=0) {
168
- parsed.query = parsed.path.substring(questionMark+1);
169
- parsed.path = parsed.path.substring(0,questionMark);
207
+ var questionMark = parsed.path.indexOf("?");
208
+ if (questionMark >= 0) {
209
+ parsed.query = parsed.path.substring(questionMark + 1);
210
+ parsed.path = parsed.path.substring(0, questionMark);
170
211
  }
171
- if (parsed.path=="/" || parsed.path=="") {
212
+ if (parsed.path == "/" || parsed.path == "") {
172
213
  parsed.segments = [];
173
214
  } else {
174
215
  parsed.segments = parsed.path.split(/\//);
175
- if (parsed.segments.length>0 && parsed.segments[0] == '' && parsed.path.length>1 && parsed.path.charAt(1) != '/') {
216
+ if (
217
+ parsed.segments.length > 0 &&
218
+ parsed.segments[0] == "" &&
219
+ parsed.path.length > 1 &&
220
+ parsed.path.charAt(1) != "/"
221
+ ) {
176
222
  // empty segment at the start, remove it
177
223
  parsed.segments.shift();
178
224
  }
179
- if (parsed.segments.length > 0 && parsed.path.length>0 && parsed.path.charAt(parsed.path.length-1) == '/' && parsed.segments[parsed.segments.length-1] == '') {
225
+ if (
226
+ parsed.segments.length > 0 &&
227
+ parsed.path.length > 0 &&
228
+ parsed.path.charAt(parsed.path.length - 1) == "/" &&
229
+ parsed.segments[parsed.segments.length - 1] == ""
230
+ ) {
180
231
  // we may have an empty the end
181
232
  // check to see if it is legimate
182
- if (parsed.path.length> 1 && parsed.path.charAt(parsed.path.length-2) != '/') {
233
+ if (
234
+ parsed.path.length > 1 &&
235
+ parsed.path.charAt(parsed.path.length - 2) != "/"
236
+ ) {
183
237
  parsed.segments.pop();
184
238
  }
185
239
  }
186
240
  // check for non-escaped characters
187
- for (var i=0; i < parsed.segments.length; i++) {
188
- var check = parsed.segments[i].split(/%[A-Za-z0-9][A-Za-z0-9]|[\ud800-\udfff][\ud800-\udfff]|[A-Za-z0-9\-\._~!$&'()*+,;=@:\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+/);
241
+ for (var i = 0; i < parsed.segments.length; i++) {
242
+ var check = parsed.segments[i].split(
243
+ /%[A-Za-z0-9][A-Za-z0-9]|[\ud800-\udfff][\ud800-\udfff]|[A-Za-z0-9\-\._~!$&'()*+,;=@:\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+/,
244
+ );
189
245
 
190
- for (var j=0; j < check.length; j++) {
191
- if (check[j].length>0) {
192
- throw new Error("Unecaped character "+check[j].charAt(0)+" ("+check[j].charCodeAt(0)+") in URI " + parsed.spec);
246
+ for (var j = 0; j < check.length; j++) {
247
+ if (check[j].length > 0) {
248
+ throw new Error(
249
+ "Unescaped character " +
250
+ check[j].charAt(0) +
251
+ " (" +
252
+ check[j].charCodeAt(0) +
253
+ ") in URI " +
254
+ parsed.spec,
255
+ );
193
256
  }
194
257
  }
195
258
  }
196
259
  }
197
260
  parsed.isGeneric = true;
198
261
  }
199
-
200
262
  }
201
263
 
202
-
203
264
  URIResolver.SCHEME = /^[A-Za-z][A-Za-z0-9\+\-\.]*\:/;
package/test/test.js CHANGED
@@ -23,8 +23,8 @@ describe("getRDFaGraph", function() {
23
23
  assert.equal(graph.toString(), expected);
24
24
  });
25
25
 
26
- it("whatever", () => {
27
- let ht = readFileSync("./bug4.html");
26
+ it.only("whatever", () => {
27
+ let ht = readFileSync("./bug6.html");
28
28
  let { document } = jsdom(ht).defaultView.window;
29
29
 
30
30
  let graph = getRDFaGraph(document, {