Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Release notes

## v1.3.1

### Fix

- Fix `SyntaxError` when a tag value was a multiline plain string (a quoted
string that spans multiple lines and contains no `{{ }}` template
expressions), e.g. an Alpine.js or hyperscript handler:

```django
{% component "small_button"
_="on click
set replyForm to closest <form />"
%}{% endcomponent %}
```

Literal newlines are now escaped when the string is compiled to a Python
literal, so the value stays a valid single-line literal. Regression from
v1.3.0. ([#37](https://github.com/django-components/djc-core/pull/37))

## v1.3.0

Drop support for Python 3.8 and 3.9.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "maturin"

[project]
name = "djc_core"
version = "1.3.0"
version = "1.3.1"
requires-python = ">=3.10, <4.0"
description = "Core library for django-components written in Rust."
keywords = ["django", "components", "html"]
Expand Down
33 changes: 33 additions & 0 deletions tests/test_template_parser__tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -1817,6 +1817,39 @@ def test_string_simple_as_kwarg(self):
assert args == []
assert kwargs == [("key", "world")]

def test_string_multiline_value(self):
# A quoted string value that spans multiple lines but contains no
# `{{ }}` expressions (e.g. an Alpine.js or hyperscript handler) must
# compile to a valid single-line Python literal, with the newline
# escaped, instead of raising `SyntaxError`. Regression from 1.3.0
# (PR #37).
tag_content = '{% component key="on click\n set x to 1" %}'
tag = parse_tag(tag_content)

expected_tag = GenericTag(
token=token(tag_content, 0, 1, 1),
name=token("component", 3, 1, 4),
attrs=[
TagAttr(
token=token('key="on click\n set x to 1"', 13, 1, 14),
key=token("key", 13, 1, 14),
value=plain_string_value('"on click\n set x to 1"', 17, 1, 18, None),
is_flag=False,
),
],
is_self_closing=False,
used_variables=[],
assigned_variables=[],
)

assert tag == expected_tag

tag_func = _simple_compile_tag(tag, tag_content)
args, kwargs = tag_func({})

assert args == []
assert kwargs == [("key", "on click\n set x to 1")]

def test_string_with_filter(self):
tag_content = "{% component 'hello'|upper %}"
tag = parse_tag(tag_content)
Expand Down