Skip to content

Commit f3543a9

Browse files
committed
Make sure that components with a dash work.
1 parent f16e675 commit f3543a9

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

django_unicorn/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
urlpatterns = (
10-
re_path("message/(?P<component_name>[\w/\.]+)", views.message, name="message"),
10+
re_path("message/(?P<component_name>[\w/\.-]+)", views.message, name="message"),
1111
path(
1212
"message", views.message, name="message"
1313
), # Only here to build the correct url in scripts.html

tests/views/message/test_message.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,27 @@ def test_message_component_not_found(client):
7272
e.exconly()
7373
== "django_unicorn.components.ComponentLoadError: 'test' component could not be loaded."
7474
)
75+
76+
77+
def test_message_component_with_dash(client):
78+
data = {"data": {}, "checksum": "FpZ5q8E2", "id": "asdf"}
79+
80+
with pytest.raises(ComponentLoadError) as e:
81+
post_json(client, data, url="/message/test-a")
82+
83+
assert (
84+
e.exconly()
85+
== "django_unicorn.components.ComponentLoadError: 'test-a' component could not be loaded."
86+
)
87+
88+
89+
def test_message_component_with_dot(client):
90+
data = {"data": {}, "checksum": "FpZ5q8E2", "id": "asdf"}
91+
92+
with pytest.raises(ComponentLoadError) as e:
93+
post_json(client, data, url="/message/test.a")
94+
95+
assert (
96+
e.exconly()
97+
== "django_unicorn.components.ComponentLoadError: 'test.a' component could not be loaded."
98+
)

0 commit comments

Comments
 (0)