8000 Fix escaping of <py-script> · Issue #1764 · pyscript/pyscript · GitHub
[go: up one dir, main page]

8000
Skip to content
Fix escaping of <py-script> #1764
Closed
Closed
@antocuni

Description

@antocuni

This is a sub issue of #1762 and it's related to the following test:

@skip_worker("NEXT: something very weird happens here")
def test_escaping_of_angle_brackets(self):
"""
Check that script tags escape angle brackets
"""
self.pyscript_run(
"""
<script type="py">import js; js.console.log("A", 1<2, 1>2)</script>
<script type="py">import js; js.console.log("B <div></div>")</script>
<py-script>import js; js.console.log("C", 1<2, 1>2)</py-script>
<py-script>import js; js.console.log("D <div></div>")</py-script>
"""
)
# in workers the order of execution is not guaranteed, better to play
# safe
lines = sorted(self.console.log.lines[-4:])
assert lines == [
"A true false",
"B <div></div>",
"C true false",
"D <div></div>",
]

Something is very weird when it comes to <py-script> parsing. If you try to run this code:

    <py-script>import js; js.console.log("C", 1<2, 1>2)</py-script>
    <py-script>import js; js.console.log("D <div></div>")</py-script>

    <py-script>
        import js
        js.console.log("E", 1<2, 1>2);
        js.console.log("F <div></div>")
    </py-script>

With PyScript classic, you get the following output, as expected:

C true false
D <div></div>
E true false
F <div></div>

With 2023.09.1RC1, something very weird happens: the "C" and "D" line are parsed correctly, but the "E" line causes troubles:
image

You can see it in action here (and you can also see that by using 2023.05.1 it works):
https://pyscript.com/@antocuni/py-script-escaping/latest

I know that <py-script> parsing is fragile and bad things can happen, but if pyscript classic was able to deal with it correctly, then pyscript next should do the same.

For reference, this is the code which was responsible to decode the content inside <py-script> tags in classic:

export function htmlDecode(input: string): string | null {
const doc = new DOMParser().parseFromString(ltrim(escape(input)), 'text/html');
return doc.documentElement.textContent;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0