diff --git a/lib/pure/htmlparser.nim b/lib/pure/htmlparser.nim index 9e1a5a1014..2d24050f2d 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 39b117d408..0967f79830 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) diff --git a/tests/stdlib/thtmlparser.nim b/tests/stdlib/thtmlparser.nim index 58b2d03770..0457585d07 100644 --- a/tests/stdlib/thtmlparser.nim +++ b/tests/stdlib/thtmlparser.nim @@ -92,6 +92,8 @@ block t6154:
+ +