1
0
mirror of https://github.com/php/php-src.git synced 2026-04-17 13:01:02 +02:00
Files
archived-php-src/ext/xmlwriter/tests/010.phpt
Dik Takken 6dac6a996e Warning promotion: Throw on writing invalid XML tag names
This change throws a ValueError when an invalid tag name is passed
to XMLWriter.

The rationale is that this indicates a programming error because
tag names typically originate from string literals or application
code generating them. This translates into either a typo or a flaw
in tag generation logic.

Closes GH-6233.
2020-09-29 16:52:47 +02:00

57 lines
1.1 KiB
PHP

--TEST--
xmlwriter_start/end_attribute()
--SKIPIF--
<?php
if (!extension_loaded("xmlwriter")) die("skip");
?>
--FILE--
<?php
$file = __DIR__.'/010.tmp';
$xw = xmlwriter_open_uri($file);
var_dump(xmlwriter_start_element($xw, "tag"));
var_dump(xmlwriter_start_attribute($xw, "attr"));
var_dump(xmlwriter_end_attribute($xw));
try {
xmlwriter_start_attribute($xw, "-1");
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
var_dump(xmlwriter_end_attribute($xw));
try {
xmlwriter_start_attribute($xw, "\"");
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
var_dump(xmlwriter_end_attribute($xw));
var_dump(xmlwriter_end_element($xw));
// Force to write and empty the buffer
xmlwriter_flush($xw, empty: true);
unset($xw);
var_dump(file_get_contents($file));
@unlink($file);
echo "Done\n";
?>
--EXPECTF--
bool(true)
bool(true)
bool(true)
xmlwriter_start_attribute(): Argument #2 ($name) must be a valid attribute name, "-1" given
bool(false)
xmlwriter_start_attribute(): Argument #2 ($name) must be a valid attribute name, """ given
bool(false)
bool(true)
string(14) "<tag attr=""/>"
Done