/usr/share/php/test/XML_Parser/tests/005.phpt is in php-xml-parser 1.3.2-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | --TEST--
XML Parser: mixing character encodings
--SKIPIF--
<?php if (!extension_loaded("xml")) echo 'skip'; ?>
--FILE--
<?php // -*- C++ -*-
//
// Test for: XML/Parser.php
// Parts tested: - mixing character encodings
//
// This is what we test:
// 1 UTF-8 -> ISO-8859-1
// 2 UTF-8 -> US-ASCII
// 3 ISO-8859-1 -> UTF-8
// 4 ISO-8859-1 -> US-ASCII
// 5 US-ASCII -> UTF-8
// 6 US-ASCII -> ISO-8859-1
//
require_once "XML/Parser.php";
class TestEncodings1 extends XML_Parser {
var $output = '';
function TestEncodings1($to, $mode, $from) {
$this->XML_Parser($from, $mode, $to);
}
function startHandler($xp, $elem, $attribs) {
$this->output .= "<$elem>";
}
function endHandler($xp, $elem) {
$this->output .= "</$elem>";
}
function cdataHandler($xp, $data) {
$this->output .= $data;
}
function test($data) {
$result = $this->parseString($data, true);
if (PEAR::isError($result)) {
return $result;
}
}
}
$xml = "<?xml version='1.0' ?>";
$input = array(
"UTF-8" => "<a>abcæøå</a>",
/* are these special chars allowed in ISO-8859-1 context??? */
"ISO-8859-1" => "<a>abcæøå</a>", // "ISO-8859-1" => "<a>abc¥<a>",
"US-ASCII" => "<a>abcaoa</a>"
);
$encodings = array_keys($input);
foreach ($input as $srcenc => $string) {
foreach ($encodings as $tgtenc) {
if ($srcenc == $tgtenc) {
continue;
}
print "Testing $srcenc -> $tgtenc: ";
$p =& new TestEncodings1($tgtenc, 'event', $srcenc);
$e = $p->test($input[$srcenc]);
if (PEAR::isError($e)) {
printf("OOPS: %s\n", $e->getMessage());
} else {
var_dump($p->output);
}
}
}
?>
--EXPECT--
Testing UTF-8 -> ISO-8859-1: string(13) "<A>abcæøå</A>"
Testing UTF-8 -> US-ASCII: string(13) "<A>abc???</A>"
Testing ISO-8859-1 -> UTF-8: string(16) "<A>abcæøå</A>"
Testing ISO-8859-1 -> US-ASCII: string(13) "<A>abc???</A>"
Testing US-ASCII -> UTF-8: string(13) "<A>abcaoa</A>"
Testing US-ASCII -> ISO-8859-1: string(13) "<A>abcaoa</A>"
|