diff options
author | Rob Richards <rrichards@php.net> | 2008-10-20 12:46:23 +0000 |
---|---|---|
committer | Rob Richards <rrichards@php.net> | 2008-10-20 12:46:23 +0000 |
commit | 6a2fe2ad1ab226418b83e8ca68c1f7de3617097f (patch) | |
tree | e5d1e7413af5a65774804d575bbb85f0efaf8308 | |
parent | 0e91f80a4d9177da375d7ec71efa0f85d5e4dad9 (diff) | |
download | php-git-6a2fe2ad1ab226418b83e8ca68c1f7de3617097f.tar.gz |
MFH: fix bug #46335 (DOMText::splitText doesn't handle multibyte characters)
add test
-rw-r--r-- | ext/dom/tests/bug46335.phpt | 35 | ||||
-rw-r--r-- | ext/dom/text.c | 8 |
2 files changed, 39 insertions, 4 deletions
diff --git a/ext/dom/tests/bug46335.phpt b/ext/dom/tests/bug46335.phpt new file mode 100644 index 0000000000..bea4ae9e7d --- /dev/null +++ b/ext/dom/tests/bug46335.phpt @@ -0,0 +1,35 @@ +--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 diff --git a/ext/dom/text.c b/ext/dom/text.c index 26479f3186..3234b4cc25 100644 --- a/ext/dom/text.c +++ b/ext/dom/text.c @@ -172,19 +172,19 @@ PHP_FUNCTION(dom_text_split_text) 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); |