Commit e043ee17 authored by Daniel Veillard's avatar Daniel Veillard
Browse files

- xpath.c: fixed xmlXPathNodeCollectAndTest() to do proper

  prefix lookup.
- parserInternals.c: fixed the bug reported by Morus Walter
  due to an off by one typo in xmlStringCurrentChar()
Daniel
parent a3bfca59
Tue Apr 17 10:08:19 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* xpath.c: fixed xmlXPathNodeCollectAndTest() to do proper
prefix lookup.
* parserInternals.c: fixed the bug reported by Morus Walter
due to an off by one typo in xmlStringCurrentChar()
Thu Apr 12 17:41:09 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr> Thu Apr 12 17:41:09 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* HTMLparser.c result/HTML/*: revamped the way the HTML * HTMLparser.c result/HTML/*: revamped the way the HTML
......
...@@ -81,6 +81,47 @@ static int xmlLittleEndian = 1; ...@@ -81,6 +81,47 @@ static int xmlLittleEndian = 1;
* I hope we won't use values > 0xFFFF anytime soon ! * I hope we won't use values > 0xFFFF anytime soon !
*/ */
/**
* xmlUTF8Strlen:
* @utf: a sequence of UTF-8 encoded bytes
*
* compute the lenght of an UTF8 string, it doesn't do a full UTF8
* checking of the content of the string.
*
* Returns the number of characters in the string or -1 in case of error
*/
int
xmlUTF8Strlen(const unsigned char *utf) {
int ret = 0;
if (utf == NULL)
return(-1);
while (*utf != 0) {
if (utf[0] & 0x80) {
if ((utf[1] & 0xc0) != 0x80)
return(-1);
if ((utf[0] & 0xe0) == 0xe0) {
if ((utf[2] & 0xc0) != 0x80)
return(-1);
if ((utf[0] & 0xf0) == 0xf0) {
if ((utf[0] & 0xf8) != 0xf0 || (utf[3] & 0xc0) != 0x80)
return(-1);
utf += 4;
} else {
utf += 3;
}
} else {
utf += 2;
}
} else {
utf++;
}
ret++;
}
return(ret);
}
/** /**
* xmlGetUTF8Char: * xmlGetUTF8Char:
* @utf: a sequence of UTF-8 encoded bytes * @utf: a sequence of UTF-8 encoded bytes
......
...@@ -166,8 +166,6 @@ xmlCharEncoding ...@@ -166,8 +166,6 @@ xmlCharEncoding
xmlDetectCharEncoding (const unsigned char* in, xmlDetectCharEncoding (const unsigned char* in,
int len); int len);
int xmlCheckUTF8 (const unsigned char *utf);
int xmlCharEncOutFunc (xmlCharEncodingHandler *handler, int xmlCharEncOutFunc (xmlCharEncodingHandler *handler,
xmlBufferPtr out, xmlBufferPtr out,
xmlBufferPtr in); xmlBufferPtr in);
...@@ -191,6 +189,9 @@ int isolat1ToUTF8 (unsigned char* out, ...@@ -191,6 +189,9 @@ int isolat1ToUTF8 (unsigned char* out,
int *outlen, int *outlen,
const unsigned char* in, const unsigned char* in,
int *inlen); int *inlen);
int xmlCheckUTF8 (const unsigned char *utf);
int xmlUTF8Strlen (const unsigned char *utf);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -166,8 +166,6 @@ xmlCharEncoding ...@@ -166,8 +166,6 @@ xmlCharEncoding
xmlDetectCharEncoding (const unsigned char* in, xmlDetectCharEncoding (const unsigned char* in,
int len); int len);
int xmlCheckUTF8 (const unsigned char *utf);
int xmlCharEncOutFunc (xmlCharEncodingHandler *handler, int xmlCharEncOutFunc (xmlCharEncodingHandler *handler,
xmlBufferPtr out, xmlBufferPtr out,
xmlBufferPtr in); xmlBufferPtr in);
...@@ -191,6 +189,9 @@ int isolat1ToUTF8 (unsigned char* out, ...@@ -191,6 +189,9 @@ int isolat1ToUTF8 (unsigned char* out,
int *outlen, int *outlen,
const unsigned char* in, const unsigned char* in,
int *inlen); int *inlen);
int xmlCheckUTF8 (const unsigned char *utf);
int xmlUTF8Strlen (const unsigned char *utf);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -1435,7 +1435,7 @@ xmlStringCurrentChar(xmlParserCtxtPtr ctxt, const xmlChar *cur, int *len) { ...@@ -1435,7 +1435,7 @@ xmlStringCurrentChar(xmlParserCtxtPtr ctxt, const xmlChar *cur, int *len) {
/* 2-byte code */ /* 2-byte code */
*len = 2; *len = 2;
val = (cur[0] & 0x1f) << 6; val = (cur[0] & 0x1f) << 6;
val |= cur[2] & 0x3f; val |= cur[1] & 0x3f;
} }
if (!IS_CHAR(val)) { if (!IS_CHAR(val)) {
if ((ctxt->sax != NULL) && if ((ctxt->sax != NULL) &&
......
...@@ -106,7 +106,7 @@ xmlSetBufferAllocationScheme(xmlBufferAllocationScheme scheme) { ...@@ -106,7 +106,7 @@ xmlSetBufferAllocationScheme(xmlBufferAllocationScheme scheme) {
*/ */
xmlBufferAllocationScheme xmlBufferAllocationScheme
xmlGetBufferAllocationScheme(void) { xmlGetBufferAllocationScheme(void) {
return xmlBufferAllocScheme; return(xmlBufferAllocScheme);
} }
/** /**
......
...@@ -4280,7 +4280,7 @@ xmlXPathStringLengthFunction(xmlXPathParserContextPtr ctxt, int nargs) { ...@@ -4280,7 +4280,7 @@ xmlXPathStringLengthFunction(xmlXPathParserContextPtr ctxt, int nargs) {
xmlChar *content; xmlChar *content;
content = xmlNodeGetContent(ctxt->context->node); content = xmlNodeGetContent(ctxt->context->node);
valuePush(ctxt, xmlXPathNewFloat(xmlStrlen(content))); valuePush(ctxt, xmlXPathNewFloat(xmlUTF8Strlen(content)));
xmlFree(content); xmlFree(content);
} }
return; return;
...@@ -4289,7 +4289,7 @@ xmlXPathStringLengthFunction(xmlXPathParserContextPtr ctxt, int nargs) { ...@@ -4289,7 +4289,7 @@ xmlXPathStringLengthFunction(xmlXPathParserContextPtr ctxt, int nargs) {
CAST_TO_STRING; CAST_TO_STRING;
CHECK_TYPE(XPATH_STRING); CHECK_TYPE(XPATH_STRING);
cur = valuePop(ctxt); cur = valuePop(ctxt);
valuePush(ctxt, xmlXPathNewFloat(xmlStrlen(cur->stringval))); valuePush(ctxt, xmlXPathNewFloat(xmlUTF8Strlen(cur->stringval)));
xmlXPathFreeObject(cur); xmlXPathFreeObject(cur);
} }
...@@ -4441,7 +4441,7 @@ xmlXPathSubstringFunction(xmlXPathParserContextPtr ctxt, int nargs) { ...@@ -4441,7 +4441,7 @@ xmlXPathSubstringFunction(xmlXPathParserContextPtr ctxt, int nargs) {
xmlChar *ret; xmlChar *ret;
/* /*
* Conformance needs to be checked !!!!! * TODO: need to be converted to UTF8 strings
*/ */
if (nargs < 2) { if (nargs < 2) {
CHECK_ARITY(2); CHECK_ARITY(2);
...@@ -4672,42 +4672,44 @@ xmlXPathNormalizeFunction(xmlXPathParserContextPtr ctxt, int nargs) { ...@@ -4672,42 +4672,44 @@ xmlXPathNormalizeFunction(xmlXPathParserContextPtr ctxt, int nargs) {
*/ */
void void
xmlXPathTranslateFunction(xmlXPathParserContextPtr ctxt, int nargs) { xmlXPathTranslateFunction(xmlXPathParserContextPtr ctxt, int nargs) {
xmlXPathObjectPtr str; xmlXPathObjectPtr str;
xmlXPathObjectPtr from; xmlXPathObjectPtr from;
xmlXPathObjectPtr to; xmlXPathObjectPtr to;
xmlBufferPtr target; xmlBufferPtr target;
int i, offset, max; int i, offset, max;
xmlChar ch; xmlChar ch;
const xmlChar *point; const xmlChar *point;
CHECK_ARITY(3); /*
* TODO: need to be converted to UTF8 strings
*/
CHECK_ARITY(3);
CAST_TO_STRING; CAST_TO_STRING;
to = valuePop(ctxt); to = valuePop(ctxt);
CAST_TO_STRING; CAST_TO_STRING;
from = valuePop(ctxt); from = valuePop(ctxt);
CAST_TO_STRING; CAST_TO_STRING;
str = valuePop(ctxt); str = valuePop(ctxt);
target = xmlBufferCreate(); target = xmlBufferCreate();
if (target) { if (target) {
max = xmlStrlen(to->stringval); max = xmlStrlen(to->stringval);
for (i = 0; (ch = str->stringval[i]); i++) { for (i = 0; (ch = str->stringval[i]); i++) {
point = xmlStrchr(from->stringval, ch); point = xmlStrchr(from->stringval, ch);
if (point) { if (point) {
/* Warning: This may not work with UTF-8 */ offset = (int)(point - from->stringval);
offset = (int)(point - from->stringval); if (offset < max)
if (offset < max) xmlBufferAdd(target, &to->stringval[offset], 1);
xmlBufferAdd(target, &to->stringval[offset], 1); } else
} else xmlBufferAdd(target, &ch, 1);
xmlBufferAdd(target, &ch, 1); }
} }
} valuePush(ctxt, xmlXPathNewString(xmlBufferContent(target)));
valuePush(ctxt, xmlXPathNewString(xmlBufferContent(target))); xmlBufferFree(target);
xmlBufferFree(target); xmlXPathFreeObject(str);
xmlXPathFreeObject(str); xmlXPathFreeObject(from);
xmlXPathFreeObject(from); xmlXPathFreeObject(to);
xmlXPathFreeObject(to);
} }
/** /**
...@@ -6542,6 +6544,7 @@ xmlXPathNodeCollectAndTest(xmlXPathParserContextPtr ctxt, ...@@ -6542,6 +6544,7 @@ xmlXPathNodeCollectAndTest(xmlXPathParserContextPtr ctxt,
xmlXPathTypeVal type = op->value3; xmlXPathTypeVal type = op->value3;
const xmlChar *prefix = op->value4; const xmlChar *prefix = op->value4;
const xmlChar *name = op->value5; const xmlChar *name = op->value5;
const xmlChar *URI = NULL;
#ifdef DEBUG_STEP #ifdef DEBUG_STEP
int n = 0, t = 0; int n = 0, t = 0;
...@@ -6558,6 +6561,11 @@ xmlXPathNodeCollectAndTest(xmlXPathParserContextPtr ctxt, ...@@ -6558,6 +6561,11 @@ xmlXPathNodeCollectAndTest(xmlXPathParserContextPtr ctxt,
CHECK_TYPE(XPATH_NODESET); CHECK_TYPE(XPATH_NODESET);
obj = valuePop(ctxt); obj = valuePop(ctxt);
addNode = xmlXPathNodeSetAdd; addNode = xmlXPathNodeSetAdd;
if (prefix != NULL) {
URI = xmlXPathNsLookup(ctxt->context, prefix);
if (URI == NULL)
XP_ERROR(XPATH_UNDEF_PREFIX_ERROR);
}
#ifdef DEBUG_STEP #ifdef DEBUG_STEP
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
...@@ -6777,7 +6785,7 @@ xmlXPathNodeCollectAndTest(xmlXPathParserContextPtr ctxt, ...@@ -6777,7 +6785,7 @@ xmlXPathNodeCollectAndTest(xmlXPathParserContextPtr ctxt,
#endif #endif
addNode(list, cur); addNode(list, cur);
} else if ((cur->ns != NULL) && } else if ((cur->ns != NULL) &&
(xmlStrEqual(prefix, (xmlStrEqual(URI,
cur->ns->href))) { cur->ns->href))) {
#ifdef DEBUG_STEP #ifdef DEBUG_STEP
n++; n++;
...@@ -6805,7 +6813,7 @@ xmlXPathNodeCollectAndTest(xmlXPathParserContextPtr ctxt, ...@@ -6805,7 +6813,7 @@ xmlXPathNodeCollectAndTest(xmlXPathParserContextPtr ctxt,
} }
} else { } else {
if ((cur->ns != NULL) && if ((cur->ns != NULL) &&
(xmlStrEqual(prefix, (xmlStrEqual(URI,
cur->ns->href))) { cur->ns->href))) {
#ifdef DEBUG_STEP #ifdef DEBUG_STEP
n++; n++;
...@@ -6828,7 +6836,7 @@ xmlXPathNodeCollectAndTest(xmlXPathParserContextPtr ctxt, ...@@ -6828,7 +6836,7 @@ xmlXPathNodeCollectAndTest(xmlXPathParserContextPtr ctxt,
} }
} else { } else {
if ((attr->ns != NULL) && if ((attr->ns != NULL) &&
(xmlStrEqual(prefix, (xmlStrEqual(URI,
attr->ns->href))) { attr->ns->href))) {
#ifdef DEBUG_STEP #ifdef DEBUG_STEP
n++; n++;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment