Skip to content

Commit a44458e

Browse files
tomchristiecraigds
authored andcommitted
Escape hyperlink URLs on lookup (encode#7059)
* Escape hyperlink URLs on lookup * Rename duplicate test Cherrypicked from master (3.13) @ fe840a3
1 parent 0c5d7b9 commit a44458e

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

rest_framework/relations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ def to_internal_value(self, data):
353353
if data.startswith(prefix):
354354
data = '/' + data[len(prefix):]
355355

356-
data = uri_to_iri(data)
356+
data = uri_to_iri(parse.unquote(data))
357357

358358
try:
359359
match = resolve(data)

tests/test_relations.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ def setUp(self):
153153
self.queryset = MockQueryset([
154154
MockObject(pk=1, name='foobar'),
155155
MockObject(pk=2, name='bazABCqux'),
156+
MockObject(pk=2, name='bazABC qux'),
156157
])
157158
self.field = serializers.HyperlinkedRelatedField(
158159
view_name='example',
@@ -191,6 +192,10 @@ def test_hyperlinked_related_lookup_url_encoded_exists(self):
191192
instance = self.field.to_internal_value('http://example.org/example/baz%41%42%43qux/')
192193
assert instance is self.queryset.items[1]
193194

195+
def test_hyperlinked_related_lookup_url_space_encoded_exists(self):
196+
instance = self.field.to_internal_value('http://example.org/example/bazABC%20qux/')
197+
assert instance is self.queryset.items[2]
198+
194199
def test_hyperlinked_related_lookup_does_not_exist(self):
195200
with pytest.raises(serializers.ValidationError) as excinfo:
196201
self.field.to_internal_value('http://example.org/example/doesnotexist/')

0 commit comments

Comments
 (0)