jmcnevin / rubypants

RubyPants: SmartyPants for Ruby
Other
29 stars 20 forks source link

rubypants translates --> into –> #1

Closed ibc closed 8 years ago

ibc commented 14 years ago

Hi, when I enable rubypants filter in a HTML page, this filter produces an error as it translates "-->" (end of commented code) into "& # 8 2 1 1 ; >" (I use space because if not github/markdown converts it into "-->".

Some browsers (Konqueror, Chrome) accept such syntax but Firefox doesn't understand that as "end of comment" and the page is wrongly rendered.

jmcnevin commented 10 years ago

And four years later, I'll see if I can do something to fix this. :smile:

snan commented 9 years ago

I was just going to report this but I also have a fix, pull from https://idiomdrottning.org/rubypants which changes one line. Insidiously, I couldn't reproduce the bug with just: RubyPants.new("").to_html but I was bit by this bug myself so I tried looking deeper. Turns out I had a nested tag in the comment like so: RubyPants.new("").to_html which triggers the bug. Anyway, pull from my repo at https://idiomdrottning.org/rubypants which changes the tag_soup regex to treat comment starts and endings as pseudo-"tags". Thanks

agriffis commented 8 years ago

@snan Any chance you'd make a PR for this? I'm curious about your fix but your site's cert is expired and it would be nice to see the changes in github's interface anyway. Otherwise, perhaps you could just cut-n-paste the diff here. Thanks!

snan commented 8 years ago

Yeah, those certs have been busted for a while :/

diff --git a/lib/rubypants/core.rb b/lib/rubypants/core.rb
index 03a210f..7f7e3a2 100644
--- a/lib/rubypants/core.rb
+++ b/lib/rubypants/core.rb
@@ -336,7 +336,7 @@ class RubyPants < String
   # Chad Miller in the Python port of SmartyPants.
   #
   def tokenize
-    tag_soup = /([^<]*)(<[^>]*>)/
+    tag_soup = /([^<]*)(<!--|<[^>]*>|-->)/

 tokens = []
jmcnevin commented 8 years ago

Sorry for keeping this PR in limbo for so long. Would either of you be interested in taking over maintenance of this gem?

https://github.com/jmcnevin/rubypants/issues/6

agriffis commented 8 years ago

@snan Thanks! I'll test that and put in a fix.

agriffis commented 8 years ago

Here is what I used:

tag_soup = /([^<]*)(<!--.*?-->|<[^>]*>)/

This treats the entire comment as an HTML tag, so that it can avoid making typographic replacements inside the comment, and also so that it doesn't treat --> as special unless it's part of a comment.