Skip to content

Commit f8c39aa

Browse files
committed
Updating python to use unquote_plus for parsing instead of unquote as best practice.
1 parent 268752b commit f8c39aa

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

python/cross_service/apigateway_covid-19_tracker/app.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def state_cases(state):
106106
logger.info("Got %s to /states/%s.", app.current_request.method, state)
107107
logger.info("JSON body: %s", app.current_request.json_body)
108108

109-
state = urllib.parse.unquote(state)
109+
state = urllib.parse.unquote_plus(state)
110110
verify_input(state, data=app.current_request.json_body)
111111

112112
response = None
@@ -145,8 +145,8 @@ def state_date_cases(state, date):
145145
"""
146146
logger.info("Got %s to /states/%s/%s.", app.current_request.method, state, date)
147147

148-
state = urllib.parse.unquote(state)
149-
date = urllib.parse.unquote(date)
148+
state = urllib.parse.unquote_plus(state)
149+
date = urllib.parse.unquote_plus(date)
150150
verify_input(state, date=date)
151151

152152
response = None

python/cross_service/aurora_rest_lending_library/library_api/app.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def list_books_by_author(author_id):
9393
:param author_id: The ID of the author to query.
9494
:return: The list of books written by the specified author.
9595
"""
96-
author_id = int(urllib.parse.unquote(author_id))
96+
author_id = int(urllib.parse.unquote_plus(author_id))
9797
return {"books": get_storage().get_books(author_id=author_id)}
9898

9999

@@ -151,7 +151,7 @@ def delete_patron(patron_id):
151151
152152
:param patron_id: The ID of the patron to remove.
153153
"""
154-
patron_id = int(urllib.parse.unquote(patron_id))
154+
patron_id = int(urllib.parse.unquote_plus(patron_id))
155155
get_storage().delete_patron(patron_id)
156156

157157

@@ -185,8 +185,8 @@ def book_lending(book_id, patron_id):
185185
:param book_id: The ID of the book.
186186
:param patron_id: The ID of the patron.
187187
"""
188-
book_id = int(urllib.parse.unquote(book_id))
189-
patron_id = int(urllib.parse.unquote(patron_id))
188+
book_id = int(urllib.parse.unquote_plus(book_id))
189+
patron_id = int(urllib.parse.unquote_plus(patron_id))
190190
if app.current_request.method == "PUT":
191191
get_storage().borrow_book(book_id, patron_id)
192192
elif app.current_request.method == "DELETE":

python/example_code/s3/s3_versioning/remove_delete_marker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def lambda_handler(event, context):
4141
task_id = task["taskId"]
4242

4343
try:
44-
obj_key = parse.unquote(task["s3Key"], encoding="utf-8")
44+
obj_key = parse.unquote_plus(task["s3Key"], encoding="utf-8")
4545
obj_version_id = task["s3VersionId"]
4646
bucket_name = task["s3BucketArn"].split(":")[-1]
4747

python/example_code/s3/s3_versioning/revise_stanza.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def lambda_handler(event, context):
3939
task = event["tasks"][0]
4040
task_id = task["taskId"]
4141
# The revision type is packed with the object key as a pipe-delimited string.
42-
obj_key, revision = parse.unquote(task["s3Key"], encoding="utf-8").split("|")
42+
obj_key, revision = parse.unquote_plus(task["s3Key"], encoding="utf-8").split("|")
4343
bucket_name = task["s3BucketArn"].split(":")[-1]
4444

4545
logger.info("Got task: apply revision %s to %s.", revision, obj_key)

0 commit comments

Comments
 (0)