v.0.6.1 URLEncoder.encode_utf8
This commit is contained in:
@@ -12,8 +12,29 @@ class URLEncoder:
|
||||
else:
|
||||
# result.append('%' + format(ord(char), '02X'))
|
||||
# Converted to % formatting:
|
||||
result.append("%%%02X" % ord(char))
|
||||
special_char = "%%%02X" % ord(char)
|
||||
|
||||
print( f"{char} --> {special_char}")
|
||||
|
||||
result.append(special_char)
|
||||
|
||||
return ''.join(result)
|
||||
|
||||
@staticmethod
|
||||
def encode_utf8(string):
|
||||
"""URL encode a string with proper UTF-8 handling"""
|
||||
result = []
|
||||
safe_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~"
|
||||
|
||||
for char in string:
|
||||
if char in safe_chars:
|
||||
result.append(char)
|
||||
else:
|
||||
# UTF-8 encoding for proper URL encoding
|
||||
utf8_bytes = char.encode('utf-8')
|
||||
for byte in utf8_bytes:
|
||||
result.append(f"%{byte:02X}")
|
||||
|
||||
return ''.join(result)
|
||||
|
||||
@staticmethod
|
||||
|
||||
Reference in New Issue
Block a user