@opentermsarchive/engine 15.0.0 → 15.1.0
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/package.json
CHANGED
|
@@ -26,3 +26,18 @@ export function removeQueryParams(webPageDOM, paramsToRemove = []) {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
+
|
|
30
|
+
const SPACE_SEPARATORS = /\p{Zs}/gu;
|
|
31
|
+
|
|
32
|
+
export function convertSpacesToStandard(webPageDOM) {
|
|
33
|
+
const walker = webPageDOM.createTreeWalker(webPageDOM.body, webPageDOM.defaultView.NodeFilter.SHOW_TEXT);
|
|
34
|
+
|
|
35
|
+
for (let node = walker.nextNode(); node; node = walker.nextNode()) {
|
|
36
|
+
const original = node.nodeValue;
|
|
37
|
+
const normalized = original.replace(SPACE_SEPARATORS, ' ');
|
|
38
|
+
|
|
39
|
+
if (normalized !== original) {
|
|
40
|
+
node.nodeValue = normalized;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { expect } from 'chai';
|
|
2
2
|
|
|
3
3
|
import createWebPageDOM from './dom.js';
|
|
4
|
-
import { removeQueryParams } from './exposedFilters.js';
|
|
4
|
+
import { convertSpacesToStandard, removeQueryParams } from './exposedFilters.js';
|
|
5
5
|
|
|
6
6
|
describe('exposedFilters', () => {
|
|
7
7
|
let webPageDOM;
|
|
@@ -265,4 +265,52 @@ fetch(trackingUrl);
|
|
|
265
265
|
});
|
|
266
266
|
});
|
|
267
267
|
});
|
|
268
|
+
|
|
269
|
+
describe('#convertSpacesToStandard', () => {
|
|
270
|
+
describe('with Unicode space separators in text', () => {
|
|
271
|
+
let element;
|
|
272
|
+
|
|
273
|
+
before(() => {
|
|
274
|
+
element = webPageDOM.createElement('p');
|
|
275
|
+
element.textContent = 'a\u00A0b\u202Fc\u2009d\u3000e';
|
|
276
|
+
webPageDOM.body.appendChild(element);
|
|
277
|
+
|
|
278
|
+
convertSpacesToStandard(webPageDOM);
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
after(() => {
|
|
282
|
+
element.remove();
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it('replaces them with a regular space', () => {
|
|
286
|
+
expect(element.textContent).to.equal('a b c d e');
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
describe('with Unicode space separators in an attribute', () => {
|
|
291
|
+
let element;
|
|
292
|
+
const className = 'label\u00A0primary';
|
|
293
|
+
|
|
294
|
+
before(() => {
|
|
295
|
+
element = webPageDOM.createElement('a');
|
|
296
|
+
element.setAttribute('class', className);
|
|
297
|
+
element.textContent = 'read\u00A0the\u00A0policy';
|
|
298
|
+
webPageDOM.body.appendChild(element);
|
|
299
|
+
|
|
300
|
+
convertSpacesToStandard(webPageDOM);
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
after(() => {
|
|
304
|
+
element.remove();
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it('leaves attribute values untouched', () => {
|
|
308
|
+
expect(element.getAttribute('class')).to.equal(className);
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it('replaces them in the text content', () => {
|
|
312
|
+
expect(element.textContent).to.equal('read the policy');
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
});
|
|
268
316
|
});
|
|
@@ -79,7 +79,7 @@ describe('Full DOM Fetcher', function () {
|
|
|
79
79
|
});
|
|
80
80
|
|
|
81
81
|
describe('#fetch', () => {
|
|
82
|
-
const config = { navigationTimeout:
|
|
82
|
+
const config = { navigationTimeout: 5000, waitForElementsTimeout: 5000, language: 'en' };
|
|
83
83
|
|
|
84
84
|
it('waits for dynamically injected elements to appear in the DOM', async () => {
|
|
85
85
|
const result = await fetch(`http://127.0.0.1:${SERVER_PORT}/dynamic`, ['.dynamic'], config);
|
|
@@ -431,7 +431,7 @@ describe('Services', () => {
|
|
|
431
431
|
expect(secondSourceDocument.filters).to.be.an('array');
|
|
432
432
|
expect(secondSourceDocument.filters).to.have.length(2);
|
|
433
433
|
expect(secondSourceDocument.filters[0]).to.be.a('function');
|
|
434
|
-
expect(secondSourceDocument.filters[0].name).to.equal(
|
|
434
|
+
expect(secondSourceDocument.filters[0].name).to.equal(realFilterNames[0]);
|
|
435
435
|
expect(secondSourceDocument.filters[1]).to.be.a('function');
|
|
436
436
|
expect(secondSourceDocument.filters[1].name).to.equal('removePrintButton');
|
|
437
437
|
});
|