You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
encode() raises IndexError when exclude contains a non-ASCII character #26
Hi! I hit this while comparing mdurl with the JavaScript mdurl. get_encode_cache builds a 128-entry table, then does cache[ord(exclude[i])] = exclude[i] for every character of exclude, so any character above U+007F is out of range:
On mdurl 0.1.2 (and main at 524d2ed), Python 3.13:
File ".../mdurl/_encode.py", line 39, in get_encode_cache
cache[ord(exclude[i])] = exclude[i]
~~~~~^^^^^^^^^^^^^^^^^
IndexError: list assignment index out of range
In JavaScript the same assignment just grows the array, and encode only looks characters below 128 up in the cache, so non-ASCII characters in exclude are ignored and still encoded:
$ node -e 'const m = require("mdurl"); console.log(JSON.stringify(m.encode("café!", "é!")))'
"caf%C3%A9!"
I expected the same here. The fix is to skip characters of 128 and above when filling the cache. I have a PR with a test.
Activity