Skip to content

Commit fe840a3

Browse files
authored
Escape hyperlink URLs on lookup (#7059)
* Escape hyperlink URLs on lookup * Rename duplicate test
1 parent 39876e6 commit fe840a3

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
@@ -344,7 +344,7 @@ def to_internal_value(self, data):
344344
if data.startswith(prefix):
345345
data = '/' + data[len(prefix):]
346346

347-
data = uri_to_iri(data)
347+
data = uri_to_iri(parse.unquote(data))
348348

349349
try:
350350
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)