Changeset 597

Show
Ignore:
Timestamp:
04/22/07 03:16:11 (1 year ago)
Author:
mikey
Message:

bugfix: data has to be encoded even if document encoding is not UTF-8
(this is a real wtf)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/xml/stubDomXMLStreamWriter.php

    r428 r597  
    44 * 
    55 * @author     Stephan Schmidt <schst@stubbles.net> 
     6 * @author     Frank Kleine <mikey@stubbles.net> 
    67 * @package    stubbles 
    78 * @subpackage xml 
     
    1920class stubDomXMLStreamWriter extends stubAbstractXMLStreamWriter implements stubXMLStreamWriter { 
    2021 
    21    /** 
    22     * List of supported features 
    23    
    24     * @var array 
    25     */ 
    26    protected $features = array(stubXMLStreamWriter::FEATURE_AS_DOM, 
    27                                stubXMLStreamWriter::FEATURE_IMPORT_WRITER); 
    28      
     22    /** 
     23    * List of supported features 
     24   
     25    * @var array 
     26    */ 
     27    protected $features = array(stubXMLStreamWriter::FEATURE_AS_DOM, 
     28                                stubXMLStreamWriter::FEATURE_IMPORT_WRITER); 
     29 
    2930    /** 
    3031     * DOM Document 
     
    9697     * @param string $data 
    9798     */ 
    98     public function writeText($data) { 
    99         $textNode = $this->doc->createTextNode($data); 
     99    public function writeText($data) 
     100    { 
     101        // data has to be encoded even if document encoding is not UTF-8 
     102        // (see http://php.net/manual/en/function.dom-domdocument-save.php#67952) 
     103        $textNode = $this->doc->createTextNode(utf8_encode($data)); 
    100104        $this->addToDom($textNode); 
    101105    } 
  • trunk/src/test/php/net/stubbles/xml/stubDomXMLStreamWriterTestCase.php

    r429 r597  
    7575 
    7676        $this->assertEqual('<?xml version="1.0" encoding="ISO-8859-1"?>' . "\n". '<root>This is text.</root>', $writer->asXML()); 
     77    } 
     78 
     79    /** 
     80     * Test creating a document with a text node containing german umlauts. 
     81     */ 
     82    public function testTextWithGermanUmlauts() { 
     83        $writer = new stubDomXMLStreamWriter(); 
     84        $writer->writeStartElement('root'); 
     85        $writer->writeText('This is text containg äöü.'); 
     86        $writer->writeEndElement(); 
     87 
     88        $this->assertEqual('<?xml version="1.0" encoding="ISO-8859-1"?>' . "\n". '<root>This is text containg äöü.</root>', $writer->asXML()); 
    7789    } 
    7890