fixed the bug in lang() as raised by Elliotte Rusty Harold added a

* xpath.c: fixed the bug in lang() as raised by Elliotte Rusty Harold
* result/XPath/tests/langsimple test/XPath/tests/langsimple
  test/XPath/docs/lang: added a regression test
Daniel
This commit is contained in:
Daniel Veillard 2005-04-06 14:09:08 +00:00
parent 6056ae93d3
commit 4ddaa56d7a
5 changed files with 90 additions and 4 deletions

View File

@ -1,3 +1,9 @@
Wed Apr 6 16:08:10 CEST 2005 Daniel Veillard <daniel@veillard.com>
* xpath.c: fixed the bug in lang() as raised by Elliotte Rusty Harold
* result/XPath/tests/langsimple test/XPath/tests/langsimple
test/XPath/docs/lang: added a regression test
Tue Apr 5 23:48:35 CEST 2005 Daniel Veillard <daniel@veillard.com>
* nanoftp.c: applied fix from Rob Richards to compile on Windows.

View File

@ -0,0 +1,60 @@
========================
Expression: //*[lang('en')]
Object is a Node Set :
Set contains 9 nodes:
1 ELEMENT b
ATTRIBUTE lang
TEXT
content=en
2 ELEMENT x
3 ELEMENT x
4 ELEMENT para
ATTRIBUTE lang
TEXT
content=en
5 ELEMENT div
ATTRIBUTE lang
TEXT
content=en
6 ELEMENT para
7 ELEMENT para
ATTRIBUTE lang
TEXT
content=EN
8 ELEMENT para
ATTRIBUTE lang
TEXT
content=en-us
9 ELEMENT para
ATTRIBUTE lang
TEXT
content=EN-US
========================
Expression: //*[lang('en-us')]
Object is a Node Set :
Set contains 2 nodes:
1 ELEMENT para
ATTRIBUTE lang
TEXT
content=en-us
2 ELEMENT para
ATTRIBUTE lang
TEXT
content=EN-US
========================
Expression: //*[lang('en-gb')]
Object is a Node Set :
Set contains 0 nodes:
========================
Expression: //*[lang('fr')]
Object is a Node Set :
Set contains 0 nodes:
========================
Expression: //*[lang('')]
Object is a Node Set :
Set contains 0 nodes:

13
test/XPath/docs/lang Normal file
View File

@ -0,0 +1,13 @@
<doc>
<x>1</x>
<b xml:lang="en">
<x>en</x>
<x>3</x>
</b>
<x>4</x>
<para xml:lang="en"/>
<div xml:lang="en"><para/></div>
<para xml:lang="EN"/>
<para xml:lang="en-us"/>
<para xml:lang="EN-US"/>
</doc>

View File

@ -0,0 +1,5 @@
//*[lang('en')]
//*[lang('en-us')]
//*[lang('en-gb')]
//*[lang('fr')]
//*[lang('')]

10
xpath.c
View File

@ -7092,8 +7092,8 @@ xmlXPathFalseFunction(xmlXPathParserContextPtr ctxt, int nargs) {
*/
void
xmlXPathLangFunction(xmlXPathParserContextPtr ctxt, int nargs) {
xmlXPathObjectPtr val;
const xmlChar *theLang;
xmlXPathObjectPtr val = NULL;
const xmlChar *theLang = NULL;
const xmlChar *lang;
int ret = 0;
int i;
@ -7108,10 +7108,12 @@ xmlXPathLangFunction(xmlXPathParserContextPtr ctxt, int nargs) {
for (i = 0;lang[i] != 0;i++)
if (toupper(lang[i]) != toupper(theLang[i]))
goto not_equal;
ret = 1;
if ((theLang[i] == 0) || (theLang[i] == '-'))
ret = 1;
}
not_equal:
xmlFree((void *)theLang);
if (theLang != NULL)
xmlFree((void *)theLang);
xmlXPathFreeObject(val);
valuePush(ctxt, xmlXPathNewBoolean(ret));
}