Skip to content

Commit

Permalink
fixed bug in url_param that considered a hyphen to not collapse with …
Browse files Browse the repository at this point in the history
…other hyphens
  • Loading branch information
Chris Eppstein committed Feb 1, 2008
1 parent ec4c03f commit 946efea
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/url_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module UrlUtils
def url_safe(s, options = {})
s = s.downcase if options.fetch(:downcase, true)
collapse = options.fetch(:collapse, true)
default_regex = /[^'a-zA-Z0-9-]#{"+" if collapse}/
default_regex = /[^'a-zA-Z0-9]#{"+" if collapse}/
replacements = options[:replacements] || { options.fetch(:char,"-") => default_regex, "" => /'#{"+" if collapse}/}
replacements.each do |replacement, regex|
s = s.gsub(regex,replacement)
Expand Down
1 change: 1 addition & 0 deletions test/url_utils_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class UrlUtilsTest < Test::Unit::TestCase

def test_url_safe
assert_equal "a1-b-z", url_safe("a1 b@ _Z!")
assert_equal "a1-b-z", url_safe("a1 b@ - Z!")
assert_equal 'a1#b#_Z', url_safe('a1 b@ _Z', :replacements => { '#', /[^a-zA-Z0-9_-]+/}, :downcase => false)
assert_equal 'a1-b2---z9', url_safe('a1 b2 z9', :collapse => false)
assert_equal 'a1_b2___z9', url_safe('a1 b2 z9', :char => '_', :collapse => false)
Expand Down

0 comments on commit 946efea

Please sign in to comment.