Skip to content

Commit

Permalink
Fix cd/dvd URLs handling
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Aug 8, 2016
1 parent c410229 commit 87815a3
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
19 changes: 18 additions & 1 deletion library/types/src/modules/URL.rb
Expand Up @@ -368,7 +368,7 @@ def Build(tokens)
userpass = Ops.add(userpass, "@")
end

url = Builtins.sformat("%1://%2", url, userpass)
url = Builtins.sformat("%1:#{scheme_separator(tokens["scheme"])}%2", url, userpass)
Builtins.y2debug("url: %1", url)

if Hostname.CheckFQ(Ops.get_string(tokens, "host", "")) ||
Expand Down Expand Up @@ -648,6 +648,23 @@ def HidePasswordToken(tokens)
publish function: :FormatURL, type: "string (map, integer)"
publish function: :HidePassword, type: "string (string)"
publish function: :HidePasswordToken, type: "map (map)"

private

# Schemes which should use a single slash.
# see #schema_separator
SINGLE_SLASH_SCHEMES = ["cd", "dvd"].freeze

# Returns the separator to be used given a scheme
#
# Schemes like 'cd' or 'dvd' should used a single '/' character to separate
# the <scheme> and the <scheme-specific-part> (bsc#991935)
#
# @param scheme [String] URI scheme
# @return [String] Separator to be used
def scheme_separator(scheme)
SINGLE_SLASH_SCHEMES.include?(scheme.downcase) ? "/" : "//"
end
end

URL = URLClass.new
Expand Down
1 change: 1 addition & 0 deletions library/types/test/Makefile.am
Expand Up @@ -2,6 +2,7 @@ TESTS = \
ip_test.rb \
ipv4_netmask_test.rb \
hostname_test.rb \
url_test.rb \
string_test.rb

TEST_EXTENSIONS = .rb
Expand Down
48 changes: 48 additions & 0 deletions library/types/test/url_test.rb
@@ -0,0 +1,48 @@
#!/usr/bin/env rspec

require_relative "test_helper"

Yast.import "URL"

describe Yast::URL do
subject { Yast::URL }

let(:url) { "https://myuser:mypassword@suse.de:1234/some-path?preview=true#contents" }
let(:tokens) do
{
"scheme" => "https",
"host" => "suse.de",
"path" => "/some-path",
"fragment" => "contents",
"user" => "myuser",
"pass" => "mypassword",
"port" => "1234",
"query" => "preview=true"
}
end

describe ".Parse" do
it "returns a hash containing the token extracted from the URL" do
expect(subject.Parse(url)).to eq(tokens)
end
end

describe ".Build" do
it "returns the URL for the given tokens" do
expect(subject.Build(tokens)).to eq(url)
end

context "given a cd/dvd URL" do
let(:tokens) do
{
"scheme" => "cd",
"query" => "device=/dev/sr0"
}
end

it "returns a URL containing which a single slash to separate the schema from the rest" do
expect(subject.Build(tokens)).to eq("cd:/?device=/dev/sr0")
end
end
end
end

0 comments on commit 87815a3

Please sign in to comment.