JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
fix noah's ark and empty cdata
authorJason Woofenden <jason@jasonwoof.com>
Thu, 24 Dec 2015 16:26:44 +0000 (11:26 -0500)
committerJason Woofenden <jason@jasonwoof.com>
Thu, 24 Dec 2015 16:26:44 +0000 (11:26 -0500)
parse-html.coffee

index 3d4db84..b3b3f7f 100644 (file)
@@ -668,18 +668,29 @@ parse_html = (args) ->
                else
                        console.log "Parse error at character #{cur} of #{txt.length}"
 
+       # http://www.w3.org/TR/html5/syntax.html#push-onto-the-list-of-active-formatting-elements
+       # "Noah's Ark clause" but with three
        afe_push = (new_el) ->
                matches = 0
                for el, i in afe
+                       if el.type is TYPE_AFE_MARKER
+                               break
                        if el.name is new_el.name and el.namespace is new_el.namespace
+                               attrs_match = true
                                for k, v of el.attrs
-                                       continue unless new_el.attrs[k] is v
-                               for k, v of new_el.attrs
-                                       continue unless el.attrs[k] is v
-                               matches += 1
-                               if matches is 3
-                                       afe.splice i, 1
-                                       break
+                                       unless new_el.attrs[k] is v
+                                               attrs_match = false
+                                               break
+                               if attrs_match
+                                       for k, v of new_el.attrs
+                                               unless el.attrs[k] is v
+                                                       attrs_match = false
+                                                       break
+                               if attrs_match
+                                       matches += 1
+                                       if matches is 3
+                                               afe.splice i, 1
+                                               break
                afe.unshift new_el
        afe_push_marker = ->
                afe.unshift new_afe_marker()
@@ -4525,7 +4536,9 @@ parse_html = (args) ->
                else
                        val = txt.substr cur, (next_gt - cur)
                        cur = next_gt + 3
-               return new_character_token val # fixfull split
+               if val.length > 0
+                       return new_character_token val # fixfull split
+               return null
 
        # 8.2.4.69 http://www.w3.org/TR/html5/syntax.html#consume-a-character-reference
        # Don't set this as a state, just call it
@@ -4648,7 +4661,7 @@ parse_html = (args) ->
        txt = txt.replace(new RegExp("\r\n", 'g'), "\n") # fixfull spec doesn't say this
        txt = txt.replace(new RegExp("\r", 'g'), "\n") # fixfull spec doesn't say this
 
-       if args.name is "tests20.dat #22"
+       if args.name is "tests23.dat #1"
                console.log "hi"
        # proccess input
        # http://www.w3.org/TR/html5/syntax.html#tree-construction