moriyoshi Sun Oct 5 21:02:29 2003 EDT
Added files:
/php-src/ext/simplexml/tests bug25756.phpt bug25756.xsd
bug25756_1.xml bug25756_2.xml
Modified files:
/php-src/ext/simplexml simplexml.c
Log:
Fixed bug #25756 (SimpleXML's validate_schema_file() broken)
Index: php-src/ext/simplexml/simplexml.c
diff -u php-src/ext/simplexml/simplexml.c:1.61 php-src/ext/simplexml/simplexml.c:1.62
--- php-src/ext/simplexml/simplexml.c:1.61 Sun Oct 5 04:08:48 2003
+++ php-src/ext/simplexml/simplexml.c Sun Oct 5 21:02:28 2003
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: simplexml.c,v 1.61 2003/10/05 08:08:48 zeev Exp $ */
+/* $Id: simplexml.c,v 1.62 2003/10/06 01:02:28 moriyoshi Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -538,7 +538,7 @@
#define SCHEMA_BLOB 1
#define SCHEMA_OBJECT 2
-#ifdef xmlSchemaParserCtxtPtr
+#ifdef LIBXML_SCHEMAS_ENABLED
/* {{{ simplexml_ce_schema_validate_file()
*/
@@ -562,28 +562,48 @@
case SCHEMA_FILE:
convert_to_string_ex(&source);
parser = xmlSchemaNewParserCtxt(Z_STRVAL_P(source));
+ if (parser == NULL) {
+ php_error_docref1(NULL TSRMLS_CC, Z_STRVAL_P(source),
E_WARNING, "Unable to load XML Schema file");
+ RETURN_FALSE;
+ }
sptr = xmlSchemaParse(parser);
- xmlSchemaFreeParserCtxt(parser);
break;
case SCHEMA_BLOB:
convert_to_string_ex(&source);
parser = xmlSchemaNewMemParserCtxt(Z_STRVAL_P(source),
Z_STRLEN_P(source));
sptr = xmlSchemaParse(parser);
- xmlSchemaFreeParserCtxt(parser);
break;
}
+ if (sptr == NULL) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Malformed XML Schema");
+ xmlSchemaFreeParserCtxt(parser);
+ RETURN_FALSE;
+ }
+
vptr = xmlSchemaNewValidCtxt(sptr);
- is_valid = xmlSchemaValidateDoc(vptr, (xmlDocPtr) sxe->document->ptr);
- xmlSchemaFree(sptr);
- xmlSchemaFreeValidCtxt(vptr);
- xmlSchemaFreeParserCtxt(parser);
- if (is_valid) {
- RETURN_TRUE;
- } else {
+ if (vptr == NULL) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to create XML
Schema validation context");
+ xmlSchemaFreeParserCtxt(parser);
RETURN_FALSE;
}
+
+ switch (xmlSchemaValidateDoc(vptr, (xmlDocPtr) sxe->document->ptr)) {
+ case 0: /* validated */
+ RETVAL_TRUE;
+ break;
+ case -1: /* internal error */
+ RETVAL_FALSE;
+ break;
+ default: /* error */
+ RETVAL_TRUE;
+ break;
+ }
+
+ xmlSchemaFree(sptr);
+ xmlSchemaFreeValidCtxt(vptr);
+ xmlSchemaFreeParserCtxt(parser);
}
/* }}} */
@@ -660,7 +680,7 @@
{
if (!strcmp(method, "xsearch")) {
simplexml_ce_xpath_search(INTERNAL_FUNCTION_PARAM_PASSTHRU);
-#ifdef xmlSchemaParserCtxtPtr
+#ifdef LIBXML_SCHEMAS_ENABLED
} else if (!strcmp(method, "validate_schema_file")) {
simplexml_ce_schema_validate(INTERNAL_FUNCTION_PARAM_PASSTHRU,
SCHEMA_FILE);
} else if (!strcmp(method, "validate_schema_buffer")) {
@@ -1049,7 +1069,7 @@
{
php_info_print_table_start();
php_info_print_table_header(2, "Simplexml support", "enabled");
- php_info_print_table_row(2, "Revision", "$Revision: 1.61 $");
+ php_info_print_table_row(2, "Revision", "$Revision: 1.62 $");
php_info_print_table_end();
}
/* }}} */
Index: php-src/ext/simplexml/tests/bug25756.phpt
+++ php-src/ext/simplexml/tests/bug25756.phpt
--TEST--
Bug #25756 (validate_schema_file() broken)
--FILE--
<?php
$dir = dirname(__FILE__);
$valid_schema_file = "$dir/bug25756.xsd";
$invalid_schema_file = "$dir/bug25756_1.xml";
$xml_file_1 = "$dir/bug25756_1.xml";
$xml_file_2 = "$dir/bug25756_2.xml";
$s = simplexml_load_file($xml_file_1);
var_dump($s);
var_dump($s->validate_schema_file($valid_schema_file));
var_dump($s->validate_schema_file($invalid_schema_file));
$s = simplexml_load_file($xml_file_2);
var_dump($s);
var_dump($s->validate_schema_file($valid_schema_file));
?>
--EXPECTF--
object(simplexml_element)#1 (1) {
["items"]=>
object(simplexml_element)#2 (1) {
["item"]=>
array(2) {
[0]=>
object(simplexml_element)#3 (2) {
["product-name"]=>
string(3) "abc"
["quantity"]=>
string(3) "123"
}
[1]=>
object(simplexml_element)#4 (2) {
["product-name"]=>
string(3) "def"
["quantity"]=>
string(3) "456"
}
}
}
}
bool(true)
Warning: Unknown: Malformed XML Schema in %s on line %d
bool(false)
object(simplexml_element)#5 (1) {
["items"]=>
object(simplexml_element)#1 (1) {
["item"]=>
array(2) {
[0]=>
object(simplexml_element)#6 (2) {
["product-name"]=>
string(3) "abc"
["quantity"]=>
string(3) "abc"
}
[1]=>
object(simplexml_element)#7 (2) {
["product-name"]=>
string(3) "abc"
["quantity"]=>
string(3) "123"
}
}
}
}
bool(false)
Index: php-src/ext/simplexml/tests/bug25756.xsd
+++ php-src/ext/simplexml/tests/bug25756.xsd
<?xml version="1.0" encoding="UTF-8" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="foo" type="foo-type" />
<xsd:complexType name="item-type">
<xsd:all>
<xsd:element name="product-name" type="xsd:string"
minOccurs="1" maxOccurs="1"/>
<xsd:element name="quantity" type="xsd:decimal"
minOccurs="1" maxOccurs="1"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="foo-type">
<xsd:sequence>
<xsd:element name="items" minoccurs="1" maxOccurs="1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="item" type="item-type"
minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
Index: php-src/ext/simplexml/tests/bug25756_1.xml
+++ php-src/ext/simplexml/tests/bug25756_1.xml
<?xml version="1.0" encoding="UTF-8" ?>
<foo>
<items>
<item>
<product-name>abc</product-name>
<quantity>123</quantity>
</item>
<item>
<product-name>def</product-name>
<quantity>456</quantity>
</item>
</items>
</foo>
Index: php-src/ext/simplexml/tests/bug25756_2.xml
+++ php-src/ext/simplexml/tests/bug25756_2.xml
<?xml version="1.0" encoding="UTF-8" ?>
<foo>
<items>
<item>
<product-name>abc</product-name>
<quantity>abc</quantity>
</item>
<item>
<product-name>abc</product-name>
<quantity>123</quantity>
</item>
</items>
</foo>
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php