Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 0f05508

Browse files
committed
Fix incorrect logic.
1 parent c911efd commit 0f05508

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

synapse/http/servlet.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,10 @@ def parse_strings_from_args(
253253
args: the twisted HTTP request.args list.
254254
name: the name of the query parameter.
255255
default: value to use if the parameter is absent, defaults to None.
256-
required : whether to raise a 400 SynapseError if the
256+
required: whether to raise a 400 SynapseError if the
257257
parameter is absent, defaults to False.
258-
allowed_values (list[bytes|unicode]): List of allowed values for the
259-
string, or None if any value is allowed, defaults to None. Must be
260-
the same type as name, if given.
258+
allowed_values: List of allowed values for the
259+
string, or None if any value is allowed, defaults to None.
261260
encoding: The encoding to decode the string content with.
262261
263262
Returns:
@@ -281,12 +280,8 @@ def parse_strings_from_args(
281280
if required:
282281
message = "Missing string query parameter %r" % (name,)
283282
raise SynapseError(400, message, errcode=Codes.MISSING_PARAM)
284-
else:
285283

286-
if isinstance(default, bytes):
287-
return default.decode(encoding)
288-
289-
return default
284+
return default
290285

291286

292287
def parse_string_from_args(
@@ -326,12 +321,15 @@ def parse_string_from_args(
326321
strings = parse_strings_from_args(
327322
args,
328323
name,
329-
default=[default],
324+
default=[default] if default is not None else None,
330325
required=required,
331326
allowed_values=allowed_values,
332327
encoding=encoding,
333328
)
334329

330+
if strings is None:
331+
return None
332+
335333
return strings[0]
336334

337335

0 commit comments

Comments
 (0)