From 9899c4525c9bedbdc3a8d7d4fbcbf8f85a4c474a Mon Sep 17 00:00:00 2001 From: rec <44084068+recloser@users.noreply.github.com> Date: Tue, 30 Oct 2018 06:58:39 +0100 Subject: Add parsing empty attribs to htmlparser (#9559) --- lib/pure/htmlparser.nim | 3 ++- lib/pure/parsexml.nim | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'lib/pure') 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) -- cgit 1.4.1-2-gfad0