aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorJeffrey Hardy <packagethief@gmail.com>2009-08-26 12:10:42 -0400
committerJeremy Kemper <jeremy@bitsweat.net>2009-08-26 14:46:38 -0700
commit66d8063c910b166e58f77ca5149a454f721667c7 (patch)
treeeb2d8cfddd7312f4f441ca4e14aa81b645ec9960 /activesupport
parent05b529ca57f75ce64540b9d34597e0c3bfe1fca7 (diff)
downloadrails-66d8063c910b166e58f77ca5149a454f721667c7.tar.gz
rails-66d8063c910b166e58f77ca5149a454f721667c7.tar.bz2
rails-66d8063c910b166e58f77ca5149a454f721667c7.zip
Correct Regexp#un/optionalize assertions and fix uncovered failures
[#3102 state:incomplete] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/core_ext/regexp.rb2
-rw-r--r--activesupport/test/core_ext/regexp_ext_test.rb12
2 files changed, 8 insertions, 6 deletions
diff --git a/activesupport/lib/active_support/core_ext/regexp.rb b/activesupport/lib/active_support/core_ext/regexp.rb
index 1a04c70d87..95d06ee6ee 100644
--- a/activesupport/lib/active_support/core_ext/regexp.rb
+++ b/activesupport/lib/active_support/core_ext/regexp.rb
@@ -9,6 +9,8 @@ class Regexp #:nodoc:
class << self
def optionalize(pattern)
+ return pattern if pattern == ""
+
case unoptionalize(pattern)
when /\A(.|\(.*\))\Z/ then "#{pattern}?"
else "(?:#{pattern})?"
diff --git a/activesupport/test/core_ext/regexp_ext_test.rb b/activesupport/test/core_ext/regexp_ext_test.rb
index f71099856d..be06a597a8 100644
--- a/activesupport/test/core_ext/regexp_ext_test.rb
+++ b/activesupport/test/core_ext/regexp_ext_test.rb
@@ -13,14 +13,14 @@ class RegexpExtAccessTests < Test::Unit::TestCase
end
def test_optionalize
- assert "a?", Regexp.optionalize("a")
- assert "(?:foo)?", Regexp.optionalize("foo")
- assert "", Regexp.optionalize("")
+ assert_equal "a?", Regexp.optionalize("a")
+ assert_equal "(?:foo)?", Regexp.optionalize("foo")
+ assert_equal "", Regexp.optionalize("")
end
def test_unoptionalize
- assert "a", Regexp.unoptionalize("a?")
- assert "foo", Regexp.unoptionalize("(?:foo)")
- assert "", Regexp.unoptionalize("")
+ assert_equal "a", Regexp.unoptionalize("a?")
+ assert_equal "foo", Regexp.unoptionalize("(?:foo)?")
+ assert_equal "", Regexp.unoptionalize("")
end
end \ No newline at end of file