]> gitweb.factorcode.org Git - factor.git/commitdiff
modern.html: Fix parser for <div><div></div></div>
authorDoug Coleman <doug.coleman@gmail.com>
Sun, 6 Feb 2022 18:07:12 +0000 (12:07 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Sun, 6 Feb 2022 18:12:32 +0000 (12:12 -0600)
It was matching on fully closed tags

extra/modern/html/html-tests.factor
extra/modern/html/html.factor

index 0399c6bda6960ffcfeadeaa7b8567217173f3db9..526c614a5ddc12af8fe6589a8afbb1a2b391d655 100644 (file)
@@ -32,4 +32,7 @@ IN: modern.html.tests
 ] [ unmatched-open-tags-error? ] must-fail-with
 
 { [[ <!-- omg omg -->]] }
-[ [[ <!-- omg omg -->]] string>html html>string ] unit-test
\ No newline at end of file
+[ [[ <!-- omg omg -->]] string>html html>string ] unit-test
+
+{ "<div><div><a/><b/><c/></div></div>" }
+[ "<div> <div>  <a/> <b/> <c/> </div> </div>" string>html html>string ] unit-test
index 758bd74ef35cbd9cc0859674159be5e526ad138f..56a086d53e49242d443ef7a762729ee4ac04d094 100644 (file)
@@ -136,19 +136,17 @@ C: <dquote> dquote
     vector n tail
     n vector shorten ;
 
-: pop-til-end ( stack quot -- seq/f )
-    [ find-last drop ] keepd swap
-    [ shorten* ] [ drop f ] if* ; inline
+: unclosed-open-tag? ( obj -- ? )
+    { [ open-tag? ] [ close-tag>> not ] } 1&& ; inline
 
 ERROR: unmatched-open-tags-error stack seq ;
 : check-tag-stack ( stack -- stack )
-    dup [
-        { [ open-tag? ] [ close-tag>> not ] } 1&&
-    ] filter [ unmatched-open-tags-error ] unless-empty ;
+    dup [ unclosed-open-tag? ] filter
+    [ unmatched-open-tags-error ] unless-empty ;
 
 ERROR: unmatched-closing-tag-error stack tag ;
 :: find-last-open-tag ( stack name -- seq )
-    stack [ { [ tag? ] [ name>> name = ] } 1&& ] find-last drop [
+    stack [ { [ unclosed-open-tag? ] [ name>> name = ] } 1&& ] find-last drop [
         stack swap shorten*
     ] [
         stack name unmatched-closing-tag-error