Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Template#match returns nil unless uri matches.

Closes #80.
  • Loading branch information...
commit b17c52818b25992902d43af23358b753a71cb547 1 parent aac36de
@therabidbanana therabidbanana authored
Showing with 11 additions and 0 deletions.
  1. +2 −0  lib/addressable/template.rb
  2. +9 −0 spec/addressable/template_spec.rb
View
2  lib/addressable/template.rb
@@ -317,6 +317,8 @@ def match(uri, processor=nil)
# First, we need to process the pattern, and extract the values.
expansions, expansion_regexp =
parse_template_pattern(pattern, processor)
+
+ return nil unless uri.to_str.match(expansion_regexp)
unparsed_values = uri.to_str.scan(expansion_regexp).flatten
if uri.to_str == pattern
View
9 spec/addressable/template_spec.rb
@@ -815,6 +815,15 @@ def self.transform(name, value)
data.mapping["foo"].should == "foo"
data.mapping["bar"].should == "banana"
end
+ it "can fail" do
+ subject.match("bar/foo").should be_nil
+ subject.match("foobaz").should be_nil
+ end
+ it "can match empty" do
+ data = subject.match("foo/baz")
+ data.mapping["foo"].should == ""
+ data.mapping["bar"].should == ""
+ end
it "lists vars" do
subject.variables.should == ["foo", "bar"]
end
Please sign in to comment.
Something went wrong with that request. Please try again.