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

uri: restrict setting protocol to file scheme #1832

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/uri/generic.rb
Expand Up @@ -360,6 +360,11 @@ def set_scheme(v)
#
def scheme=(v)
check_scheme(v)
if v == 'file'
set_user(nil)
set_password(nil)
set_port(nil)
end
set_scheme(v)
v
end
Expand Down
9 changes: 9 additions & 0 deletions test/uri/test_generic.rb
Expand Up @@ -156,6 +156,15 @@ def test_parse
assert_equal(nil, url.user)
assert_equal(nil, url.password)
assert_equal(nil, url.userinfo)

# 10
# https://url.spec.whatwg.org/#cannot-have-a-username-password-port
url = URI.parse('http://user:pass@example.com:1234')
url.scheme = 'file'
assert_equal(nil, url.user)
assert_equal(nil, url.password)
assert_equal(nil, url.userinfo)
assert_equal(nil, url.port)
end

def test_merge
Expand Down