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
How to create file URI from file path (Support Request / Documentation Bug) #87
This example does not work anymore, since URI::escape() is gone. How are we supposed to replace this? Let's pretend we have a path on disk like '/home/username/Überraschung zum Geburtstag/🎂/ideas.md'
Using URI::encode_www_form_component
uri = URI::File.build(path: URI::encode_www_form_component("/home/username/Überraschung zum Geburtstag/🎂/ideas.md"))
# throws URI::InvalidComponentError, because the path_separators are encoded as well. And spaces are encoded as +
Using URI::encode_uri_component
uri = URI::File.build(path: URI::encode_uri_component("/home/username/Überraschung zum Geburtstag/🎂/ideas.md"))
# throws URI::InvalidComponentError, because the path_separators are encoded as well. Spaces are encoded as %20
The best I have come up with so far is using URI::Parser.new.escape:
uri = URI::File.build(path: URI::Parser.new.escape("/home/username/Überraschung zum Geburtstag/🎂/ideas.md"))
uri.to_s # => "file:///home/username/%C3%9Cberraschung%20zum%20Geburtstag/%F0%9F%8E%82/ideas.md"
Is this correct? Is this the intended way? Should the comment be updated? Or do we need to create a better way to encode paths.
Activity
nobu commentedon Jul 14, 2025
Fixed by #146.