mirror of
https://github.com/php/php-src.git
synced 2025-08-16 14:08:47 +02:00
Some more DOM testing and code style updates (#12933)
This commit is contained in:
parent
d6299206dd
commit
82baeeb196
3 changed files with 89 additions and 40 deletions
|
@ -904,9 +904,13 @@ PHP_METHOD(DOM_Document, createAttributeNS)
|
||||||
root = xmlDocGetRootElement(docp);
|
root = xmlDocGetRootElement(docp);
|
||||||
if (root != NULL) {
|
if (root != NULL) {
|
||||||
errorcode = dom_check_qname(ZSTR_VAL(name), &localname, &prefix, uri_len, ZSTR_LEN(name));
|
errorcode = dom_check_qname(ZSTR_VAL(name), &localname, &prefix, uri_len, ZSTR_LEN(name));
|
||||||
/* TODO: switch to early goto-out style error-checking */
|
if (UNEXPECTED(errorcode != 0)) {
|
||||||
if (errorcode == 0) {
|
goto error;
|
||||||
if (xmlValidateName((xmlChar *) localname, 0) == 0) {
|
}
|
||||||
|
if (UNEXPECTED(xmlValidateName((xmlChar *) localname, 0) != 0)) {
|
||||||
|
errorcode = INVALID_CHARACTER_ERR;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
/* If prefix is "xml" and namespace is not the XML namespace, then throw a "NamespaceError" DOMException. */
|
/* If prefix is "xml" and namespace is not the XML namespace, then throw a "NamespaceError" DOMException. */
|
||||||
if (UNEXPECTED(!zend_string_equals_literal(uri, "http://www.w3.org/XML/1998/namespace") && xmlStrEqual(BAD_CAST prefix, BAD_CAST "xml"))) {
|
if (UNEXPECTED(!zend_string_equals_literal(uri, "http://www.w3.org/XML/1998/namespace") && xmlStrEqual(BAD_CAST prefix, BAD_CAST "xml"))) {
|
||||||
errorcode = NAMESPACE_ERR;
|
errorcode = NAMESPACE_ERR;
|
||||||
|
@ -947,10 +951,6 @@ PHP_METHOD(DOM_Document, createAttributeNS)
|
||||||
}
|
}
|
||||||
xmlSetNs(nodep, nsptr);
|
xmlSetNs(nodep, nsptr);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
errorcode = INVALID_CHARACTER_ERR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
php_error_docref(NULL, E_WARNING, "Document Missing Root Element");
|
php_error_docref(NULL, E_WARNING, "Document Missing Root Element");
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
|
|
16
ext/dom/tests/DOMDocument_recover_write.phpt
Normal file
16
ext/dom/tests/DOMDocument_recover_write.phpt
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
--TEST--
|
||||||
|
DOMDocument::$recover write
|
||||||
|
--EXTENSIONS--
|
||||||
|
dom
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
$dom = new DOMDocument;
|
||||||
|
var_dump($dom->recover);
|
||||||
|
$dom->recover = true;
|
||||||
|
var_dump($dom->recover);
|
||||||
|
echo $dom->saveXML();
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
bool(false)
|
||||||
|
bool(true)
|
||||||
|
<?xml version="1.0"?>
|
33
ext/dom/tests/DOMDocument_version_write.phpt
Normal file
33
ext/dom/tests/DOMDocument_version_write.phpt
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
--TEST--
|
||||||
|
DOMDocument::$version write
|
||||||
|
--EXTENSIONS--
|
||||||
|
dom
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
class MyThrowingStringable {
|
||||||
|
public function __toString(): string {
|
||||||
|
throw new Exception("An exception was thrown");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$dom = new DOMDocument;
|
||||||
|
var_dump($dom->version);
|
||||||
|
$dom->version = "foobar";
|
||||||
|
var_dump($dom->version);
|
||||||
|
echo $dom->saveXML();
|
||||||
|
|
||||||
|
try {
|
||||||
|
$dom->version = new MyThrowingStringable;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
echo $e->getMessage(), "\n";
|
||||||
|
}
|
||||||
|
var_dump($dom->version);
|
||||||
|
echo $dom->saveXML();
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
string(3) "1.0"
|
||||||
|
string(6) "foobar"
|
||||||
|
<?xml version="foobar"?>
|
||||||
|
An exception was thrown
|
||||||
|
string(6) "foobar"
|
||||||
|
<?xml version="foobar"?>
|
Loading…
Add table
Add a link
Reference in a new issue