summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorrec <44084068+recloser@users.noreply.github.com>2018-10-30 06:58:39 +0100
committerAndreas Rumpf <rumpf_a@web.de>2018-10-30 06:58:39 +0100
commit9899c4525c9bedbdc3a8d7d4fbcbf8f85a4c474a (patch)
treea6d13c17fedcabb3e5b92158d3bdc73fb434a145 /lib
parent69c0a9c6fb688d382d83c165860006977dd6bf04 (diff)
downloadNim-9899c4525c9bedbdc3a8d7d4fbcbf8f85a4c474a.tar.gz
Add parsing empty attribs to htmlparser (#9559)
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/htmlparser.nim3
-rw-r--r--lib/pure/parsexml.nim8
2 files changed, 9 insertions, 2 deletions
diff --git a/lib/pure/htmlparser.nim b/lib/pure/htmlparser.nim
index 9e1a5a101..2d24050f2 100644
--- a/lib/pure/htmlparser.nim
+++ b/lib/pure/htmlparser.nim
@@ -2014,7 +2014,8 @@ proc parseHtml*(s: Stream, filename: string,
   ## Parses the XML from stream `s` and returns a ``XmlNode``. Every
   ## occurred parsing error is added to the `errors` sequence.
   var x: XmlParser
-  open(x, s, filename, {reportComments, reportWhitespace, allowUnquotedAttribs})
+  open(x, s, filename, {reportComments, reportWhitespace, allowUnquotedAttribs,
+    allowEmptyAttribs})
   next(x)
   # skip the DOCTYPE:
   if x.kind == xmlSpecial: next(x)
diff --git a/lib/pure/parsexml.nim b/lib/pure/parsexml.nim
index 39b117d40..0967f7983 100644
--- a/lib/pure/parsexml.nim
+++ b/lib/pure/parsexml.nim
@@ -189,6 +189,7 @@ type
     reportWhitespace,      ## report whitespace
     reportComments         ## report comments
     allowUnquotedAttribs   ## allow unquoted attribute values (for HTML)
+    allowEmptyAttribs      ## allow empty attributes (without explicit value)
 
   XmlParser* = object of BaseLexer ## the parser object.
     a, b, c: string
@@ -621,10 +622,15 @@ proc parseAttribute(my: var XmlParser) =
   if my.a.len == 0:
     markError(my, errGtExpected)
     return
+
+  let startPos = my.bufpos
   parseWhitespace(my, skip=true)
   if my.buf[my.bufpos] != '=':
-    markError(my, errEqExpected)
+    if allowEmptyAttribs notin my.options or
+        (my.buf[my.bufpos] != '>' and my.bufpos == startPos):
+      markError(my, errEqExpected)
     return
+
   inc(my.bufpos)
   parseWhitespace(my, skip=true)