vmg / redcarpet

The safe Markdown parser, reloaded.
MIT License
4.98k stars 524 forks source link

Smartypants converts ' into ‘ #680

Open edudepetris opened 5 years ago

edudepetris commented 5 years ago

I found a possible bug, I think.

Please feel free to close it if I wrong. Btw: Amazing library 👏

Example input

<div title='<strong>This breaks everything</strong>'>
  <strong>This breaks everything</strong>
</div>

Fail

text = "<div title='<strong>This breaks everything</strong>'><strong>This breaks everything</strong></div>"

Redcarpet::Render::SmartyPants.render(text)

Output

<div title='<strong>This breaks everything</strong>&lsquo;><strong>This breaks everything</strong></div>

Expected output

I think it &lsquo;> should be '>

I've tested it with these versions:

  1. 3.3.3
  2. 3.5.0
edudepetris commented 5 years ago

Adding a test case

  # /test/smarty_pants_test.rb

  def test_that_smart_is_confused_by_ending_tag_quotes
    rd = @pants.render(%(<p title='<strong>This breaks everything</strong>'></p>))
    assert_equal %(<p title='<strong>This breaks everything</strong>'></p>), rd
  end
............................................................................................................................F
===============================================================================================================================
     58: 
     59:   def test_that_smart_is_confused_by_ending_tag_quotes
     60:     rd = @pants.render(%(<p title='<strong>This breaks everything</strong>'></p>))
  => 61:     assert_equal %(<p title='<strong>This breaks everything</strong>'></p>), rd
     62:   end
     63: end
/Users/edudepetris/Limbo/redcarpet/test/smarty_pants_test.rb:61:in `test_that_smart_is_confused_by_ending_tag_quotes'
<"<p title='<strong>This breaks everything</strong>'></p>"> expected but was
<"<p title='<strong>This breaks everything</strong>&lsquo;></p>">

diff:
? <p title='<strong>This breaks everything</strong>'      ></p>
?                                                  &lsquo;     
Failure: test_that_smart_is_confused_by_ending_tag_quotes(SmartyPantsTest)
===============================================================================================================================