rrichards               Mon Oct 20 12:44:28 2008 UTC

  Added files:                 
    /php-src/ext/dom/tests      bug46335.phpt 

  Modified files:              
    /php-src/ext/dom    text.c 
  Log:
  fix bug #46335 (DOMText::splitText doesn't handle multibyte characters)
  add test
  
http://cvs.php.net/viewvc.cgi/php-src/ext/dom/text.c?r1=1.39&r2=1.40&diff_format=u
Index: php-src/ext/dom/text.c
diff -u php-src/ext/dom/text.c:1.39 php-src/ext/dom/text.c:1.40
--- php-src/ext/dom/text.c:1.39 Wed Sep 10 15:39:43 2008
+++ php-src/ext/dom/text.c      Mon Oct 20 12:44:28 2008
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: text.c,v 1.39 2008/09/10 15:39:43 rrichards Exp $ */
+/* $Id: text.c,v 1.40 2008/10/20 12:44:28 rrichards Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -171,19 +171,19 @@
        if (cur == NULL) {
                RETURN_FALSE;
        }
-       length = xmlStrlen(cur);
+       length = xmlUTF8Strlen(cur);
 
        if (offset > length || offset < 0) {
                xmlFree(cur);
                RETURN_FALSE;
        }
 
-       first = xmlStrndup(cur, offset);
-       second = xmlStrdup(cur + offset);
+       first = xmlUTF8Strndup(cur, offset);
+       second = xmlUTF8Strsub(cur, offset, length - offset);
        
        xmlFree(cur);
 
-       xmlNodeSetContentLen(node, first, offset);
+       xmlNodeSetContent(node, first);
        nnode = xmlNewDocText(node->doc, second);
        
        xmlFree(first);

http://cvs.php.net/viewvc.cgi/php-src/ext/dom/tests/bug46335.phpt?view=markup&rev=1.1
Index: php-src/ext/dom/tests/bug46335.phpt
+++ php-src/ext/dom/tests/bug46335.phpt
--TEST--
Bug #46335 (DOMText::splitText doesn't handle multibyte characters).
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php 
$textascii = 'This is an "example" of using DOM splitText';
$text = 'This is an ‘example’ of using DOM splitText';
$start = 30;
$length = 3;

$dom = new DOMDocument('1.0', 'UTF-8');
$node = $dom->createTextNode($textascii);
$dom->appendChild($node);

print "Text: $node->textContent\n";

$matched = $node->splitText($start);
$matched->splitText($length);
print "splitText (ASCII): $matched->textContent\n";

$node = $dom->createTextNode($text);
$dom->appendChild($node);

print "Text: $node->textContent\n";

$matched = $node->splitText($start);
$matched->splitText($length);
print "splitText (UTF-8): $matched->textContent\n";
?>
--EXPECT--
Text: This is an "example" of using DOM splitText
splitText (ASCII): DOM
Text: This is an ‘example’ of using DOM splitText
splitText (UTF-8): DOM



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to