Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid double-escaping in url_escape #30

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 35 additions & 33 deletions apko/private/util.bzl
Original file line number Diff line number Diff line change
@@ -1,42 +1,44 @@
"utility functions"

# Define the list of reserved characters and their percent-encoded values
_reserved_chars = {
" ": "%20",
"!": "%21",
'"': "%22",
"#": "%23",
"$": "%24",
"%": "%25",
"&": "%26",
"'": "%27",
"(": "%28",
")": "%29",
"*": "%2A",
"+": "%2B",
",": "%2C",
"/": "%2F",
":": "%3A",
";": "%3B",
"<": "%3C",
"=": "%3D",
">": "%3E",
"?": "%3F",
"@": "%40",
"[": "%5B",
"\\": "%5C",
"]": "%5D",
"^": "%5E",
"`": "%60",
"{": "%7B",
"|": "%7C",
"}": "%7D",
"~": "%7E",
}
_reserved_chars = [
# To avoid double-escaping, percent must be handled before any other replacements.
("%", "%25"),
#
(" ", "%20"),
("!", "%21"),
('"', "%22"),
("#", "%23"),
("$", "%24"),
("&", "%26"),
("'", "%27"),
("(", "%28"),
(")", "%29"),
("*", "%2A"),
("+", "%2B"),
(",", "%2C"),
("/", "%2F"),
(":", "%3A"),
(";", "%3B"),
("<", "%3C"),
("=", "%3D"),
(">", "%3E"),
("?", "%3F"),
("@", "%40"),
("[", "%5B"),
("\\", "%5C"),
("]", "%5D"),
("^", "%5E"),
("`", "%60"),
("{", "%7B"),
("|", "%7C"),
("}", "%7D"),
("~", "%7E"),
]

def _url_escape(url):
"""Replace reserved characters with their percent-encoded values"""
for char, encoded_value in _reserved_chars.items():
for char, encoded_value in _reserved_chars:
url = url.replace(char, encoded_value)

return url
Expand Down