Skip to content

Commit

Permalink
encode/decode dollar symbol (fixes #2079)
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Nov 24, 2023
1 parent 94729f8 commit 7562ca9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion nicegui/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ def build_response(self, request: Request, status_code: int = 200) -> Response:
'elements': elements.replace('&', '&')
.replace('<', '&lt;')
.replace('>', '&gt;')
.replace('`', '&#96;'),
.replace('`', '&#96;')
.replace('$', '&#36;'),
'head_html': self.head_html,
'body_html': '<style>' + '\n'.join(vue_styles) + '</style>\n' + self.body_html + '\n' + '\n'.join(vue_html),
'vue_scripts': '\n'.join(vue_scripts),
Expand Down
3 changes: 2 additions & 1 deletion nicegui/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
const loaded_components = new Set();

const raw_elements = String.raw`{{ elements | safe }}`;
const elements = JSON.parse(raw_elements.replace(/&#96;/g, '`')
const elements = JSON.parse(raw_elements.replace(/&#36;/g, '$')
.replace(/&#96;/g, '`')
.replace(/&gt;/g, '>')
.replace(/&lt;/g, '<')
.replace(/&amp;/g, '&'));
Expand Down
7 changes: 7 additions & 0 deletions tests/test_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,10 @@ def test_invalid_tags(screen: Screen):
ui.element(tag)

screen.open('/')


def test_bad_characters(screen: Screen):
ui.html(r'& <test> ` ${foo}')

screen.open('/')
screen.should_contain(r'& <test> ` ${foo}')

0 comments on commit 7562ca9

Please sign in to comment.