Skip to content

Commit

Permalink
Fixed issue with join operator extraction.
Browse files Browse the repository at this point in the history
  • Loading branch information
sporkmonger committed Nov 15, 2008
1 parent f34c621 commit 9bef9d0
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/addressable/uri.rb
Expand Up @@ -856,7 +856,7 @@ def extract_join_operator(value, processor, argument, variables, mapping)
end
mapping[name] = parsed_value
end
if (parsed_variables & variables) != variables
if (parsed_variables & variables) != parsed_variables
raise TemplateOperatorAbortedError,
"Template operator 'join' variable mismatch: " +
"#{parsed_variables.inspect}, #{variables.inspect}"
Expand Down
95 changes: 95 additions & 0 deletions spec/addressable/uri_spec.rb
Expand Up @@ -3399,6 +3399,40 @@ def self.match(name)
end
end

describe Addressable::URI, "when given a simple mapping" do
before do
@mapping = {
"foo" => "fred",
"bar" => "barney",
"baz" => ""
}
end

it "should result in 'foo=fred&bar=barney&baz=' when used to expand " +
"'{-join|&|foo,bar,baz,qux}'" do
Addressable::URI.expand_template(
"{-join|&|foo,bar,baz,qux}",
@mapping
).to_s.should == "foo=fred&bar=barney&baz="
end

it "should result in 'bar=barney' when used to expand " +
"'{-join|&|bar}'" do
Addressable::URI.expand_template(
"{-join|&|bar}",
@mapping
).to_s.should == "bar=barney"
end

it "should result in '' when used to expand " +
"'{-join|&|qux}'" do
Addressable::URI.expand_template(
"{-join|&|qux}",
@mapping
).to_s.should == ""
end
end

describe Addressable::URI, "when given a mapping containing values " +
"that are already percent-encoded" do
before do
Expand Down Expand Up @@ -4005,6 +4039,67 @@ def to_str
end
end

describe Addressable::URI, " when parsed from " +
"'http://example.com/a/b/c/?one=1&two=2#foo'" do
before do
@uri = Addressable::URI.parse(
"http://example.com/a/b/c/?one=1&two=2#foo"
)
end

it "should have the correct mapping when extracting values " +
"using the pattern " +
"'http://{host}/{-suffix|/|segments}?{-join|&|one,two}\#{fragment}'" do
@uri.extract_mapping(
"http://{host}/{-suffix|/|segments}?{-join|&|one,two}\#{fragment}"
).should == {
"host" => "example.com",
"segments" => ["a", "b", "c"],
"one" => "1",
"two" => "2",
"fragment" => "foo"
}
end

it "should not match when extracting values " +
"using the pattern " +
"'http://{host}/{-suffix|/|segments}?{-join|&|one}\#{fragment}'" do
@uri.extract_mapping(
"http://{host}/{-suffix|/|segments}?{-join|&|one}\#{fragment}"
).should == nil
end

it "should not match when extracting values " +
"using the pattern " +
"'http://{host}/{-suffix|/|segments}?{-join|&|bogus}\#{fragment}'" do
@uri.extract_mapping(
"http://{host}/{-suffix|/|segments}?{-join|&|bogus}\#{fragment}"
).should == nil
end

it "should not match when extracting values " +
"using the pattern " +
"'http://{host}/{-suffix|/|segments}?{-join|&|one,bogus}\#{fragment}'" do
@uri.extract_mapping(
"http://{host}/{-suffix|/|segments}?{-join|&|one,bogus}\#{fragment}"
).should == nil
end

it "should not match when extracting values " +
"using the pattern " +
"'http://{host}/{-suffix|/|segments}?{-join|&|one,two,bogus}\#{fragment}'" do
@uri.extract_mapping(
"http://{host}/{-suffix|/|segments}?{-join|&|one,two,bogus}\#{fragment}"
).should == {
"host" => "example.com",
"segments" => ["a", "b", "c"],
"one" => "1",
"two" => "2",
"fragment" => "foo"
}
end
end

describe Addressable::URI, "when given a pattern with bogus operators" do
before do
@uri = Addressable::URI.parse("http://example.com/a/b/c/")
Expand Down

0 comments on commit 9bef9d0

Please sign in to comment.