Skip to content

Escape quotes in client events #42

@Lgt2x

Description

@Lgt2x
from trame.app import get_server
from trame_client.widgets import html
from trame_client.ui.html import DivLayout

server = get_server(client_type="vue3")
state, ctrl = server.state, server.controller

with DivLayout(server) as layout:
    Button("Exec", click="console.log(\"test\");", classes="alertMsg")

server.start()

This code is failing, because the generated Vue template for the button is invalid:

<button class="alertMsg" @click="console.log("test");">

The callback contains double quotes, and is interpolated within a double-quoted string. The Javascript console error message is cryptic to the non-initiated Uncaught (in promise) SyntaxError: 17.

This is also a problem for the JSEval exec function, that also uses VueJS events to execute code on the client.

There are multiple ways to prevent this error, including escaping quotes as HTML console.log(&quot;test&quot;);. I suggest we perform this escaping in the AbstractElement.events function, or at least warn the user and prevent generating invalid template code.

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