Skip to content

Commit 521f6fb

Browse files
committed
Follow up for src / worker validation
1 parent cdf6eae commit 521f6fb

File tree

5 files changed

+14
-5
lines changed

5 files changed

+14
-5
lines changed

core.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/core.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/core.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

esm/worker/url.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
import { dedent } from '../utils.js';
22

3+
const hasCommentsOnly = text => !text
4+
.replace(/\/\*[\s\S]*?\*\//g, '')
5+
.replace(/^\s*(?:\/\/|#).*/gm, '')
6+
.trim()
7+
;
8+
39
/* c8 ignore start */ // tested via integration
410
export default element => {
511
const { src, worker } = element.attributes;
612
if (worker) {
713
let { value } = worker;
814
// throw on worker values as ambiguous
915
// @see https://github.com/pyscript/polyscript/issues/43
10-
if (value) throw new SyntaxError(`Invalid worker attribute: ${value}`);
16+
if (value) throw new SyntaxError('Invalid worker attribute');
1117
value = src?.value;
1218
if (!value) {
1319
// throw on empty src attributes
@@ -32,5 +38,8 @@ export default element => {
3238
}
3339
return value;
3440
}
41+
// validate ambiguous cases with src and not empty/commented content
42+
if (src && !hasCommentsOnly(element.textContent))
43+
throw new SyntaxError('Invalid content');
3544
};
3645
/* c8 ignore stop */

test/integration/_shared.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,6 @@ exports.python = {
114114
page.on('console', msg => logs.push(msg.text()));
115115
await page.goto(url);
116116
await page.waitForSelector('html.error');
117-
await expect(logs.pop()).toBe('Invalid worker attribute: nope.py');
117+
await expect(logs.pop()).toBe('Invalid worker attribute');
118118
},
119119
};

0 commit comments

Comments
 (0)