8000 Fix #1764 - Unescape `innerHTML` artifacts (#1767) · pyscript/pyscript@97699ea · GitHub
[go: up one dir, main page]

Skip to content

Commit 97699ea

Browse files
Fix #1764 - Unescape innerHTML artifacts (#1767)
1 parent c6aaacd commit 97699ea

File tree

5 files changed

+78
-43
lines changed

5 files changed

+78
-43
lines changed

pyscript.core/package-lock.json

Lines changed: 33 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyscript.core/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@
3333
"dependencies": {
3434
"@ungap/with-resolvers": "^0.1.0",
3535
"basic-devtools": "^0.1.6",
36-
"polyscript": "^0.4.6"
36+
"polyscript": "^0.4.7"
3737
},
3838
"devDependencies": {
3939
"@rollup/plugin-node-resolve": "^15.2.1",
4040
"@rollup/plugin-terser": "^0.4.3",
4141
"eslint": "^8.50.0",
42-
"rollup": "^3.29.3",
42+
"rollup": "^3.29.4",
4343
"rollup-plugin-postcss": "^4.0.2",
4444
"rollup-plugin-string": "^3.0.0",
4545
"static-handler": "^0.4.2",

pyscript.core/src/core.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ import {
99
XWorker,
1010
} from "../node_modules/polyscript/esm/index.js";
1111
import { queryTarget } from "../node_modules/polyscript/esm/script-handler.js";
12-
import { dedent, dispatch } from "../node_modules/polyscript/esm/utils.js";
12+
import {
13+
dedent,
14+
dispatch,
15+
unescape,
16+
} from "../node_modules/polyscript/esm/utils.js";
1317
import { Hook } from "../node_modules/polyscript/esm/worker/hooks.js";
1418

1519
import "./all-done.js";
@@ -108,12 +112,12 @@ for (const [TYPE, interpreter] of TYPES) {
108112

109113
if (asText) return dedent(tag.textContent);
110114

115+
const code = dedent(unescape(tag.innerHTML));
111116
console.warn(
112117
`Deprecated: use <script type="${TYPE}"> for an always safe content parsing:\n`,
113-
tag.innerHTML,
118+
code,
114119
);
115-
116-
return dedent(tag.innerHTML);
120+
return code;
117121
};
118122

119123
// define the module as both `<script type="py">` and `<py-script>`

pyscript.core/test/html-decode.html

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,29 @@
77
<body>
88
<body>
99
<py-script>import js; js.console.log(1<2, 1>2)</py-script>
10-
<py-script>js.console.log("<div></div>")</py-script>
10+
<py-script>import js; js.console.log("<div></div>")</py-script>
11+
<script type="py">
12+
import js
13+
js.console.log("A", 1<2, 1>2)
14+
js.console.log("B <div></div>")
15+
</script>
16+
<py-script>
17+
import js
18+
js.console.log("C", 1<2, 1>2)
19+
js.console.log("D <div></div>")
20+
</py-script>
21+
<py-script worker>import js; js.console.log(1<2, 1>2)</py-script>
22+
<py-script worker>import js; js.console.log("<div></div>")</py-script>
23+
<script type="py" worker>
24+
import js
25+
js.console.log("A", 1<2, 1>2)
26+
js.console.log("B <div></div>")
27+
</script>
28+
<py-script worker>
29+
import js
30+
js.console.log("C", 1<2, 1>2)
31+
js.console.log("D <div></div>")
32+
</py-script>
1133
</body>
1234
</body>
1335
</html>

pyscript.core/tests/integration/test_01_basic.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_execution_thread(self):
4343
in_worker = str(in_worker).lower()
4444
assert self.console.log.lines[-1] == f"worker? {in_worker}"
4545

46-
@skip_worker('NEXT: it should show a nice error on the page')
46+
@skip_worker("NEXT: it should show a nice error on the page")
4747
def test_no_cors_headers(self):
4848
self.disable_cors_headers()
4949
self.pyscript_run(
@@ -58,7 +58,7 @@ def test_no_cors_headers(self):
5858
assert self.headers == {}
5959
if self.execution_thread == "main" B3E9 :
6060
self.wait_for_pyscript()
61-
assert self.console.log.lines == ['hello']
61+
assert self.console.log.lines == ["hello"]
6262
self.assert_no_banners()
6363
else:
6464
# XXX adapt and fix the test
@@ -73,7 +73,6 @@ def test_no_cors_headers(self):
7373
alert_banner = self.page.wait_for_selector(".alert-banner")
7474
assert expected_alert_banner_msg in alert_banner.inner_text()
7575

76-
7776
def test_print(self):
7877
self.pyscript_run(
7978
"""
@@ -159,18 +158,22 @@ def test_execution_in_order(self):
159158
"four",
160159
]
161160

162-
@skip_worker("NEXT: something very weird happens here")
163161
def test_escaping_of_angle_brackets(self):
164162
"""
165163
Check that script tags escape angle brackets
166164
"""
167165
self.pyscript_run(
168166
"""
169-
<script type="py">import js; js.console.log("A", 1<2, 1>2)</script>
170-
<script type="py">import js; js.console.log("B <div></div>")</script>
171-
<py-script>import js; js.console.log("C", 1<2, 1>2)</py-script>
172-
<py-script>import js; js.console.log("D <div></div>")</py-script>
173-
167+
<script type="py">
168+
import js
169+
js.console.log("A", 1<2, 1>2)
170+
js.console.log("B <div></div>")
171+
</script>
172+
<py-script>
173+
import js
174+
js.console.log("C", 1<2, 1>2)
175+
js.console.log("D <div></div>")
176+
</py-script>
174177
"""
175178
)
176179
# in workers the order of execution is not guaranteed, better to play

0 commit comments

Comments
 (0)
0