NewsDownloader: Add URL path encoding to improve request handling#14870
Merged
Conversation
Frenzie
reviewed
Jan 23, 2026
Comment on lines
+219
to
+231
| local encoded_path = "" | ||
|
|
||
| for i = 1, #path do | ||
| local char = path:sub(i, i) | ||
| if char:match("[a-zA-Z0-9.-_~!$&'()*+,;=:@]") then -- Unreserved characters | ||
| encoded_path = encoded_path .. char | ||
| else | ||
| local code = string.byte(char) | ||
| encoded_path = encoded_path .. string.format("%%%02X", code) | ||
| end | ||
| end | ||
|
|
||
| parsed_url.path = encoded_path |
Member
There was a problem hiding this comment.
You can do this using something like
for c in str:gmatch"." do
print(c)
endWhich would avoid the overhead of allocating all those strings (granted, probably not too much of a concern here).
But just file that away for future reference, because please use util.urlEncode() instead.
| socketutil:set_timeout(timeout, maxtime or 30) | ||
| local request = { | ||
| url = url, | ||
| url = path_percentage_encode(url), |
Member
There was a problem hiding this comment.
I'd skip the separate function to keep it simple to follow. Just stick two or three lines above, along the lines of:
local parsed_url = socket_url.parse(url)
local path = parsed_url.path -- not really sure what that or "/" is about though, better to just ignore it
if path then
parsed_url.path = util.urlEncode(path)
url = socket_url.build(parsed_url)
end
Contributor
Author
|
Hi @Frenzie! Just implemented your suggestions, I didn't notice the |
Frenzie
reviewed
Jan 26, 2026
Member
|
Thanks! |
0xstillb
pushed a commit
to 0xstillb/koreader-thai
that referenced
this pull request
May 9, 2026
…dling (koreader#14870) For example for blank spaces in path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original problem
I use the News/Feed Downloader to download webcomics. As I am using it, there are some images that could not be downloaded if it contains blank spaces in its path, i.e. [https://fandogamia.com/fanternet/content/nadadelotromundo/Curso de cocina para exdioses - 034.jpg](https://fandogamia.com/fanternet/content/nadadelotromundo/Curso de cocina para exdioses - 034.jpg).
Solution
I have implemented a small function that, according to the RFC 3986, converts invalid path characters to their percent-encoded equivalent.
This change is