[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
[xml] [patch] line number counting for CDATA
- From: Dave Beckett <dave beckett bristol ac uk>
- To: xml gnome org
- Subject: [xml] [patch] line number counting for CDATA
- Date: Fri, 26 Mar 2004 15:55:46 +0000
I mentioned this a while back, but now I can demonstrate it using the
standard libxml2 utils and have a fix for it.
If you take the attached XML file (ok, rdf/xml but that's not important)
and run it like this:
$ xmllint --version
xmllint: using libxml version 20607
compiled with: DTDValid FTP HTTP HTML C14N Catalog XPath XPointer XInclude Iconv Unicode Regexps Automata Schemas
$ xmllint bad-cdata-libxml.rdf
bad-cdata-libxml.rdf:13: parser error : EntityRef: expecting ';'
blah blah A&B
^
$ xmllint --push bad-cdata-libxml.rdf
bad-cdata-libxml.rdf:11: parser error : EntityRef: expecting ';'
blah blah A&B
^
so there is a difference of 2 which is caused by the two newlines in
the CDATA section not being counted in the push parser.
The error is that the SKIP macro in parser.c does not count newlines
that it crosses, which affects CDATA. The solution is to make a new
SKIPL macro that does, and use it in the two places it needs it.
Patch attached, working against CVS sources right now.
Dave
<?xml version="1.0" encoding="iso-8859-1"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns="http://purl.org/rss/1.0/">
<rdf:Description rdf:about="http://example.org/">
<description><![CDATA[
<p>html stuff
</p>]]></description>
<dc:description>
blah blah A&B
</dc:description>
</rdf:Description>
</rdf:RDF>
Index: parser.c
===================================================================
RCS file: /cvs/gnome/gnome-xml/parser.c,v
retrieving revision 1.364
diff -u -r1.364 parser.c
--- parser.c 22 Mar 2004 15:22:24 -0000 1.364
+++ parser.c 26 Mar 2004 15:46:47 -0000
@@ -1260,6 +1260,21 @@
xmlPopInput(ctxt); \
} while (0)
+#define SKIPL(val) do { \
+ int skipl; \
+ for(skipl=0; skipl<val; skipl++) { \
+ if (*(ctxt->input->cur) == '\n') { \
+ ctxt->input->line++; ctxt->input->col = 1; \
+ } else ctxt->input->col++; \
+ ctxt->nbChars++; \
+ ctxt->input->cur++; \
+ } \
+ if (*ctxt->input->cur == '%') xmlParserHandlePEReference(ctxt); \
+ if ((*ctxt->input->cur == 0) && \
+ (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) \
+ xmlPopInput(ctxt); \
+ } while (0)
+
#define SHRINK if ((ctxt->progressive == 0) && \
(ctxt->input->cur - ctxt->input->base > 2 * INPUT_CHUNK) && \
(ctxt->input->end - ctxt->input->cur < 2 * INPUT_CHUNK)) \
@@ -9250,7 +9265,7 @@
ctxt->input->cur,
XML_PARSER_BIG_BUFFER_SIZE);
}
- SKIP(XML_PARSER_BIG_BUFFER_SIZE);
+ SKIPL(XML_PARSER_BIG_BUFFER_SIZE);
ctxt->checkIndex = 0;
}
goto done;
@@ -9264,7 +9279,7 @@
ctxt->sax->characters(ctxt->userData,
ctxt->input->cur, base);
}
- SKIP(base + 3);
+ SKIPL(base + 3);
ctxt->checkIndex = 0;
ctxt->instate = XML_PARSER_CONTENT;
#ifdef DEBUG_PUSH
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]