Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Certain characters, such as the cent symbol (¢) create slashes after conversion to ascii (c/) and aren't caught by the current slash scrubbing #58

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/stringex/string_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ def to_html(lite_mode = false)
# Create a URI-friendly representation of the string. This is used internally by
# acts_as_url[link:classes/Stringex/ActsAsUrl/ClassMethods.html#M000012]
# but can be called manually in order to generate an URI-friendly version of any string.
# Since the ascii conversion can produce slash characters, we need to post-process the string to strip them.
def to_url(options = {})
remove_formatting(options).downcase.replace_whitespace("-").collapse("-").limit(options[:limit])
raw = remove_formatting(options).downcase
raw.gsub!(/\s*(\\|\/)\s*/, " ") unless options[:allow_slash]
raw.replace_whitespace("-").collapse("-").limit(options[:limit])
end

def limit(lim = nil)
Expand Down Expand Up @@ -181,6 +184,7 @@ def convert_misc_characters(options = {})
/(\S|^)\.(\S)/ => '\1 dot \2',
/(\s|^)\$(\d*)(\s|$)/ => '\2 dollars',
/(\s|^)£(\d*)(\s|$)/u => '\2 pounds',
/(\s|^)(\d*)¢(\s|$)/u => '\2 cents',
/(\s|^)¥(\d*)(\s|$)/u => '\2 yen',
/\s*\*\s*/ => "star",
/\s*%\s*/ => "percent",
Expand Down