From 50d593787f0fddc67f27ad926df06c6bab25883e Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Thu, 20 Oct 2016 23:44:55 +0200 Subject: [PATCH] fixes #1518 --- lib/pure/parsexml.nim | 32 +++++++++++++++++--------------- lib/pure/xmlparser.nim | 3 +++ 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/lib/pure/parsexml.nim b/lib/pure/parsexml.nim index d16a553023..aa4a13ecf5 100644 --- a/lib/pure/parsexml.nim +++ b/lib/pure/parsexml.nim @@ -142,9 +142,9 @@ proc kind*(my: XmlParser): XmlEventKind {.inline.} = template charData*(my: XmlParser): string = ## returns the character data for the events: ``xmlCharData``, ## ``xmlWhitespace``, ``xmlComment``, ``xmlCData``, ``xmlSpecial`` - ## Raises an assertion in debug mode if ``my.kind`` is not one + ## Raises an assertion in debug mode if ``my.kind`` is not one ## of those events. In release mode, this will not trigger an error - ## but the value returned will not be valid. + ## but the value returned will not be valid. assert(my.kind in {xmlCharData, xmlWhitespace, xmlComment, xmlCData, xmlSpecial}) my.a @@ -152,49 +152,49 @@ template charData*(my: XmlParser): string = template elementName*(my: XmlParser): string = ## returns the element name for the events: ``xmlElementStart``, ## ``xmlElementEnd``, ``xmlElementOpen`` - ## Raises an assertion in debug mode if ``my.kind`` is not one + ## Raises an assertion in debug mode if ``my.kind`` is not one ## of those events. In release mode, this will not trigger an error - ## but the value returned will not be valid. + ## but the value returned will not be valid. assert(my.kind in {xmlElementStart, xmlElementEnd, xmlElementOpen}) my.a template entityName*(my: XmlParser): string = ## returns the entity name for the event: ``xmlEntity`` - ## Raises an assertion in debug mode if ``my.kind`` is not + ## Raises an assertion in debug mode if ``my.kind`` is not ## ``xmlEntity``. In release mode, this will not trigger an error - ## but the value returned will not be valid. + ## but the value returned will not be valid. assert(my.kind == xmlEntity) my.a template attrKey*(my: XmlParser): string = ## returns the attribute key for the event ``xmlAttribute`` - ## Raises an assertion in debug mode if ``my.kind`` is not + ## Raises an assertion in debug mode if ``my.kind`` is not ## ``xmlAttribute``. In release mode, this will not trigger an error - ## but the value returned will not be valid. + ## but the value returned will not be valid. assert(my.kind == xmlAttribute) my.a template attrValue*(my: XmlParser): string = ## returns the attribute value for the event ``xmlAttribute`` - ## Raises an assertion in debug mode if ``my.kind`` is not + ## Raises an assertion in debug mode if ``my.kind`` is not ## ``xmlAttribute``. In release mode, this will not trigger an error - ## but the value returned will not be valid. + ## but the value returned will not be valid. assert(my.kind == xmlAttribute) my.b template piName*(my: XmlParser): string = ## returns the processing instruction name for the event ``xmlPI`` - ## Raises an assertion in debug mode if ``my.kind`` is not + ## Raises an assertion in debug mode if ``my.kind`` is not ## ``xmlPI``. In release mode, this will not trigger an error - ## but the value returned will not be valid. + ## but the value returned will not be valid. assert(my.kind == xmlPI) my.a template piRest*(my: XmlParser): string = ## returns the rest of the processing instruction for the event ``xmlPI`` - ## Raises an assertion in debug mode if ``my.kind`` is not + ## Raises an assertion in debug mode if ``my.kind`` is not ## ``xmlPI``. In release mode, this will not trigger an error - ## but the value returned will not be valid. + ## but the value returned will not be valid. assert(my.kind == xmlPI) my.b @@ -636,12 +636,14 @@ proc rawGetTok(my: var XmlParser) = proc getTok(my: var XmlParser) = while true: + let lastKind = my.kind rawGetTok(my) case my.kind of xmlComment: if my.options.contains(reportComments): break of xmlWhitespace: - if my.options.contains(reportWhitespace): break + if my.options.contains(reportWhitespace) or lastKind in {xmlCharData, xmlComment, xmlEntity}: + break else: break proc next*(my: var XmlParser) = diff --git a/lib/pure/xmlparser.nim b/lib/pure/xmlparser.nim index 2fe08afb7e..22bd259b76 100644 --- a/lib/pure/xmlparser.nim +++ b/lib/pure/xmlparser.nim @@ -164,3 +164,6 @@ when isMainModule: var xml = loadXml(filePath, errors) assert(errors.len == 0, "The file tests/testdata/doc1.xml should be parsed without errors.") + block bug1518: + var err: seq[string] = @[] + assert $parsexml(newStringStream"One & two", "temp.xml", err) == "One & two"