fixed a problem with the HTML parser pointed by Gary Benson sdding the

* python/generator.py python/libxml2class.txt : fixed a problem
  with the HTML parser pointed by Gary Benson
* python/tests/Makefile.am python/tests/pushSAXhtml.py: sdding the
  example
Daniel
This commit is contained in:
Daniel Veillard 2002-05-13 10:33:30 +00:00
parent e48a318f0f
commit 3cd7240da4
6 changed files with 103 additions and 8 deletions

View File

@ -1,3 +1,10 @@
Mon May 13 12:32:22 CEST 2002 Daniel Veillard <daniel@veillard.com>
* python/generator.py python/libxml2class.txt : fixed a problem
with the HTML parser pointed by Gary Benson
* python/tests/Makefile.am python/tests/pushSAXhtml.py: sdding the
example
Thu 09 May 2002 11:19:00 AM PDT Aleksey Sanin <aleksey@aleksey.com>
* parser.c: fixed bug #81159 (memory growth in SAX)

View File

@ -530,6 +530,8 @@ classes_type = {
"xmlXPathParserContextPtr": ("._o", "xpathParserContext(_obj=%s)", "xpathParserContext"),
"xmlParserCtxtPtr": ("._o", "parserCtxt(_obj=%s)", "parserCtxt"),
"xmlParserCtxt *": ("._o", "parserCtxt(_obj=%s)", "parserCtxt"),
"htmlParserCtxtPtr": ("._o", "parserCtxt(_obj=%s)", "parserCtxt"),
"htmlParserCtxt *": ("._o", "parserCtxt(_obj=%s)", "parserCtxt"),
"xmlCatalogPtr": ("._o", "catalog(_obj=%s)", "catalog"),
"xmlURIPtr": ("._o", "URI(_obj=%s)", "URI"),
}

View File

@ -6,13 +6,9 @@
# functions from module HTMLparser
htmlFreeParserCtxt()
htmlHandleOmittedElem()
htmlIsScriptAttribute()
htmlParseCharRef()
htmlParseChunk()
htmlParseDoc()
htmlParseElement()
htmlParseFile()
# functions from module HTMLtree
@ -440,6 +436,12 @@ Class parserCtxt()
validate()
wellFormed()
# functions from module HTMLparser
htmlFreeParserCtxt()
htmlParseCharRef()
htmlParseChunk()
htmlParseElement()
# functions from module parser
clearParserCtxt()
freeParserCtxt()

View File

@ -8,6 +8,7 @@ PYTESTS= \
xpathext.py \
push.py \
pushSAX.py \
pushSAXhtml.py \
error.py \
serialize.py\
validate.py \

64
python/tests/pushSAXhtml.py Executable file
View File

@ -0,0 +1,64 @@
#!/usr/bin/python -u
import sys
import libxml2
# Memory debug specific
libxml2.debugMemory(1)
log = ""
class callback:
def startDocument(self):
global log
log = log + "startDocument:"
def endDocument(self):
global log
log = log + "endDocument:"
def startElement(self, tag, attrs):
global log
log = log + "startElement %s %s:" % (tag, attrs)
def endElement(self, tag):
global log
log = log + "endElement %s:" % (tag)
def characters(self, data):
global log
log = log + "characters: %s:" % (data)
def warning(self, msg):
global log
log = log + "warning: %s:" % (msg)
def error(self, msg):
global log
log = log + "error: %s:" % (msg)
def fatalError(self, msg):
global log
log = log + "fatalError: %s:" % (msg)
handler = callback()
ctxt = libxml2.htmlCreatePushParser(handler, "<foo", 4, "test.xml")
chunk = " url='tst'>b"
ctxt.htmlParseChunk(chunk, len(chunk), 0)
chunk = "ar</foo>"
ctxt.htmlParseChunk(chunk, len(chunk), 1)
ctxt=None
reference = "startDocument:startElement foo {'url': 'tst'}:characters: bar:endElement foo:endDocument:"
if log != reference:
print "Error got: %s" % log
print "Exprected: %s" % reference
sys.exit(1)
# Memory debug specific
libxml2.cleanupParser()
if libxml2.debugMemory(1) == 0:
print "OK"
else:
print "Memory leak %d bytes" % (libxml2.debugMemory(1))
libxml2.dumpMemory()

27
xpath.c
View File

@ -7024,6 +7024,18 @@ xmlXPathParseNameComplex(xmlXPathParserContextPtr ctxt, int qualified) {
return(NULL);
return(xmlStrndup(buf, len));
}
#define MAX_FRAC 20
static double my_pow10[MAX_FRAC] = {
1.0, 10.0, 100.0, 1000.0, 10000.0,
100000.0, 1000000.0, 10000000.0, 100000000.0, 1000000000.0,
10000000000.0, 100000000000.0, 1000000000000.0, 10000000000000.0,
100000000000000.0,
1000000000000000.0, 10000000000000000.0, 100000000000000000.0,
1000000000000000000.0, 10000000000000000000.0
};
/**
* xmlXPathStringEvalNumber:
* @str: A string to scan
@ -7044,7 +7056,6 @@ double
xmlXPathStringEvalNumber(const xmlChar *str) {
const xmlChar *cur = str;
double ret;
double mult = 1;
int ok = 0;
int isneg = 0;
int exponent = 0;
@ -7087,15 +7098,23 @@ xmlXPathStringEvalNumber(const xmlChar *str) {
#endif
if (*cur == '.') {
int v, frac = 0;
double fraction = 0;
cur++;
if (((*cur < '0') || (*cur > '9')) && (!ok)) {
return(xmlXPathNAN);
}
while ((*cur >= '0') && (*cur <= '9')) {
mult /= 10;
ret = ret + (*cur - '0') * mult;
while (((*cur >= '0') && (*cur <= '9')) && (frac < MAX_FRAC)) {
v = (*cur - '0');
fraction = fraction * 10 + v;
frac = frac + 1;
cur++;
}
fraction /= my_pow10[frac];
ret = ret + fraction;
while ((*cur >= '0') && (*cur <= '9'))
cur++;
}
if ((*cur == 'e') || (*cur == 'E')) {
cur++;