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

Use URI::RFC2396_Parser #1329

Merged
merged 3 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions gemfile_steep/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ PLATFORMS
arm64-darwin-21
arm64-darwin-22
arm64-darwin-23
arm64-darwin-24
x86_64-linux

DEPENDENCIES
Expand Down
6 changes: 4 additions & 2 deletions lib/steep/path_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ module Steep
module PathHelper
module_function

URIParser = URI::RFC2396_Parser.new()

def to_pathname(uri, dosish: Gem.win_platform?)
uri = URI.parse(uri)
if uri.scheme == "file"
path = uri.path or raise
path.sub!(%r{^/([a-zA-Z])(:|%3A)//?}i, '\1:/') if dosish
path = URI::DEFAULT_PARSER.unescape(path)
path = URIParser.unescape(path)
Pathname(path)
end
end
Expand All @@ -21,7 +23,7 @@ def to_uri(path, dosish: Gem.win_platform?)
if dosish
str_path.insert(0, "/") if str_path[0] != "/"
end
str_path = URI::DEFAULT_PARSER.escape(str_path)
str_path = URIParser.escape(str_path)
URI::File.build(path: str_path)
end
end
Expand Down
4 changes: 4 additions & 0 deletions rbs_collection.steep.lock.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ gems:
version: '0'
source:
type: stdlib
- name: benchmark
version: '0'
source:
type: stdlib
- name: bigdecimal
version: '0'
source:
Expand Down
2 changes: 2 additions & 0 deletions sig/steep/path_helper.rbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Steep
module PathHelper
URIParser: URI::RFC2396_Parser

# Receives a String that represents a *file* URI and returns a Pathname
#
# Returns `nil` when the schema of given URI is not `file://`.
Expand Down