Skip to content


Subversion checkout URL

You can clone with
Download ZIP


remove pipe characters from URLs #46

wants to merge 1 commit into from

4 participants


I have a project that uses to_url on page titles, which sometimes have pipes. URI.parse barfed. It's a legal character but should be encoded, so I figured this is the place to make the change.


did some reading and this seems to cause some issues in other areas too so seems like a good call. i'm just not sure that removing it is the right replacement. not sure it's not either. just thinking about possible word transcriptions like happen with $ and / => dollar and slash. thinking "pipe" makes the most sense but not sure how many usages of this wouldn't fit? what's yr thoughts?


I've only seen it used as a separator between the site name and page title. Replacing it with a literal "pipe" should be fine, just don't think it adds any value to the cases I've seen. The authors aren't trying to say "pipe." That said, I could see cases where they would be, and it's not going to make a big difference for me either way.


yeah i have no idea. will sleep on this and do something in the morning.


I vote +1. We use to_url in mongoid-slug and basically want all special characters removed.


+1 for this. Just fixed it myself, then thought to check to see if there was a pull request fixing the problem. :/ I agree that simply removing the pipe is the right choice. Most of the time when I've seen a pipe it's used as a separator, not to provide semantic meaning.

@stormsilver stormsilver referenced this pull request from a commit in stormsilver/stringex
@stormsilver stormsilver Added pipe striping code from upstream pull req #46, moved dup slug c…
…hecking code so that it doesn't run unless necessary.

yeah i have no strong feelings about transliterating that as 'pipe' so this seems fine.


feeling like idiot but i can't find the commit to pull in here in yr repo


manually added this in 4fdc79d. thanks for the work on this. sorry i was so slack in taking care of it. @stormsilver, i'd already merged in an equivalent for yr dup slug optimization. good job though.

@rsl rsl closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 25, 2012
  1. @wopr42

    remove pipe characters from URLs

    wopr42 committed
This page is out of date. Refresh to see the latest.
2  lib/stringex/string_extensions.rb
@@ -162,7 +162,7 @@ def convert_misc_characters(options = {})
replaced = " #{replaced} " unless replaced =~ /\\1/
dummy.gsub!(found, replaced)
- dummy = dummy.gsub(/(^|\w)'(\w|$)/, '\1\2').gsub(/[\.,:;()\[\]\?!\^'"_]/, " ")
+ dummy = dummy.gsub(/(^|\w)'(\w|$)/, '\1\2').gsub(/[\.,:;()\[\]\?!\^'"_\|]/, " ")
# Replace runs of whitespace in string. Defaults to a single space but any replacement
4 test/string_extensions_test.rb
@@ -50,7 +50,9 @@ def test_to_url
"foo = bar and bar=foo" =>
"Will…This Work?" =>
- "will-dot-dot-dot-this-work"
+ "will-dot-dot-dot-this-work",
+ "with a | pipe" =>
+ "with-a-pipe"
}.each do |html, plain|
assert_equal plain, html.to_url
Something went wrong with that request. Please try again.