From 4793fd6709f2d5dbebf6da39ed7eeef2e0df6daa Mon Sep 17 00:00:00 2001 From: Andrew Bloomgarden Date: Wed, 9 Jun 2010 15:48:41 -0700 Subject: [PATCH] RegexpWithNamedGroups's parsing of in-group options now doesn't treat ?i-mx: (and the like) as captures. --- lib/rack/mount/regexp_with_named_groups.rb | 2 +- test/fixtures/basic_set_map_19.rb | 1 + test/test_recognition.rb | 4 ++++ test/test_regexp_with_named_groups.rb | 7 +++++++ 4 files changed, 13 insertions(+), 1 deletions(-) diff --git a/lib/rack/mount/regexp_with_named_groups.rb b/lib/rack/mount/regexp_with_named_groups.rb index 8103df6..caabff6 100644 --- a/lib/rack/mount/regexp_with_named_groups.rb +++ b/lib/rack/mount/regexp_with_named_groups.rb @@ -35,7 +35,7 @@ module Rack::Mount while scanner.skip_until(/\(/) if scanner.scan(/\?:<([^>]+)>/) @names << scanner[1] - elsif scanner.scan(/\?:/) + elsif scanner.scan(/\?(i?m?x?\-?i?m?x?)?:/) # ignore noncapture else @names << nil diff --git a/test/fixtures/basic_set_map_19.rb b/test/fixtures/basic_set_map_19.rb index f21fa80..563e504 100644 --- a/test/fixtures/basic_set_map_19.rb +++ b/test/fixtures/basic_set_map_19.rb @@ -77,6 +77,7 @@ BasicSetMap = Proc.new do |set| set.add_route(EchoApp, { :path_info => %r{^/regexp/baz/[a-z]+/[0-9]+$} }, { :controller => 'foo' }, :complex_regexp_fail) set.add_route(EchoApp, { :path_info => %r{^/escaped/\(foo\)$} }, { :controller => 'escaped/foo' }, :escaped_optional_capture) set.add_route(EchoApp, { :path_info => %r{^/ignorecase/(?(?i-mx:josh))$} }, { :controller => 'ignorecase' }, :ignore) + set.add_route(EchoApp, { :path_info => %r{^/ignorecase/(?(?i-mx:josh))/(?[0-9]+)$} }, { :controller => 'ignorecase' }, :ignore_with_id) set.add_route(EchoApp, { :path_info => %r{^/ignorecase/foo$}i }, { :controller => 'ignorecase' }) set.add_route(EchoApp, { :path_info => (/^\/extended\/ # comment foo # bar diff --git a/test/test_recognition.rb b/test/test_recognition.rb index 62d8325..3e67ae3 100644 --- a/test/test_recognition.rb +++ b/test/test_recognition.rb @@ -343,6 +343,10 @@ class TestRecognition < Test::Unit::TestCase get '/ignorecase/Foo' assert_success assert_equal({ :controller => 'ignorecase' }, routing_args) + + get '/ignorecase/josh/1' + assert_success + assert_equal({ :controller => 'ignorecase', :name => 'josh', :id => '1' }, routing_args) end def test_extended_path diff --git a/test/test_regexp_with_named_groups.rb b/test/test_regexp_with_named_groups.rb index e4aed62..b068739 100644 --- a/test/test_regexp_with_named_groups.rb +++ b/test/test_regexp_with_named_groups.rb @@ -45,5 +45,12 @@ unless supports_named_captures? assert_equal(['baz'], regexp.names) assert_equal({ 'baz' => [1]}, regexp.named_captures) end + + def test_ignores_noncapture_regexp_options + regexp = RegexpWithNamedGroups.new(/foo(?:(?i-mx:bar))(?:baz)/) + assert_equal(/foo((?i-mx:bar))(baz)/, regexp) + assert_equal(['bar', 'baz'], regexp.names) + assert_equal({ 'bar' => [1], 'baz' => [2]}, regexp.named_captures) + end end end -- 1.7.0.4