Skip to content

Commit

Permalink
bugfix: use [[:space:]] instead of \s when detecting double/single op…
Browse files Browse the repository at this point in the history
…ening quotes to account for unicode non-breaking space character (\u00a0)
  • Loading branch information
jeffplang committed Feb 4, 2015
1 parent b017a0b commit 4f8ae30
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/rubypants/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def educate_quotes(str)
dec_dashes = "#{entity(:en_dash)}|#{entity(:em_dash)}"

# Get most opening single quotes:
str.gsub!(/(\s| |--|&[mn]dash;|#{dec_dashes}|&#x201[34];)'(?=\w)/,
str.gsub!(/([[:space:]]| |--|&[mn]dash;|#{dec_dashes}|&#x201[34];)'(?=\w)/,
'\1' + entity(:single_left_quote))

# Single closing quotes:
Expand All @@ -284,7 +284,7 @@ def educate_quotes(str)
entity(:single_left_quote))

# Get most opening double quotes:
str.gsub!(/(\s| |--|&[mn]dash;|#{dec_dashes}|&#x201[34];)"(?=\w)/,
str.gsub!(/([[:space:]]| |--|&[mn]dash;|#{dec_dashes}|&#x201[34];)"(?=\w)/,
'\1' + entity(:double_left_quote))

# Double closing quotes:
Expand Down
3 changes: 3 additions & 0 deletions test/rubypants_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ def test_quotes

assert_rp_equal '<b>"</b>', "<b>&#8220;</b>"
assert_rp_equal 'foo<b>"</b>', "foo<b>&#8221;</b>"

assert_rp_equal "foo\u00a0\"bar\"", "foo\u00a0&#8220;bar&#8221;"
assert_rp_equal "foo\u00a0'bar'", "foo\u00a0&#8216;bar&#8217;"
end

def test_dashes
Expand Down

0 comments on commit 4f8ae30

Please sign in to comment.