com php-src: Fixed #75317 - UConverter::setDestinationEncoding changes source instead of destinatination: NEWS ext/intl/converter/converter.c
ext/intl/tests/bug75317.phpt

From: Date: Thu, 19 Oct 2017 11:02:22 +0000
Subject: com php-src: Fixed #75317 - UConverter::setDestinationEncoding changes source instead of destinatination: NEWS ext/intl/converter/converter.c
ext/intl/tests/bug75317.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-99806@lists.php.net to get a copy of this message
Commit: 80c3b078b8f4da054d95bc35b7951bb3f6987b5d Author: Nester <andrew.nester.dev@gmail.com> Mon, 9 Oct 2017 14:26:44 +0000 Committer: Joe Watkins <krakjoe@php.net> Thu, 19 Oct 2017 12:02:22 +0100 Parents: aa143515d656ef915ed6636382a88da9792ee796 Branches: PHP-7.0 PHP-7.1 PHP-7.2 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=80c3b078b8f4da054d95bc35b7951bb3f6987b5d Log: Fixed #75317 - UConverter::setDestinationEncoding changes source instead of destinatination Bugs: https://bugs.php.net/75317 Changed paths: M NEWS M ext/intl/converter/converter.c A ext/intl/tests/bug75317.phpt Diff: diff --git a/NEWS b/NEWS index 8d451c6..8e8f6af 100644 --- a/NEWS +++ b/NEWS @@ -19,6 +19,10 @@ PHP NEWS . Fixed bug #75301 (Exif extension has built in revision version). (Peter Kokot) +- intl: + . Fixed bug #75317 (UConverter::setDestinationEncoding changes source instead + of destination). (andrewnester) + - OCI8: . Fixed valgrind issue. (Tianfang Yang) diff --git a/ext/intl/converter/converter.c b/ext/intl/converter/converter.c index 2b5cf98..537a8e5 100644 --- a/ext/intl/converter/converter.c +++ b/ext/intl/converter/converter.c @@ -411,7 +411,7 @@ static zend_bool php_converter_set_encoding(php_converter_object *objval, ZEND_BEGIN_ARG_INFO_EX(php_converter_set_encoding_arginfo, 0, ZEND_RETURN_VALUE, 1) ZEND_ARG_INFO(0, encoding) ZEND_END_ARG_INFO(); -static void php_converter_do_set_encoding(UConverter *cnv, INTERNAL_FUNCTION_PARAMETERS) { +static void php_converter_do_set_encoding(UConverter **pcnv, INTERNAL_FUNCTION_PARAMETERS) { php_converter_object *objval = CONV_GET(getThis()); char *enc; size_t enc_len; @@ -423,21 +423,21 @@ static void php_converter_do_set_encoding(UConverter *cnv, INTERNAL_FUNCTION_PAR } intl_errors_reset(&objval->error); - RETURN_BOOL(php_converter_set_encoding(objval, &(objval->src), enc, enc_len)); + RETURN_BOOL(php_converter_set_encoding(objval, pcnv, enc, enc_len)); } /* }}} */ /* {{{ proto bool UConverter::setSourceEncoding(string encoding) */ static PHP_METHOD(UConverter, setSourceEncoding) { php_converter_object *objval = CONV_GET(getThis()); - php_converter_do_set_encoding(objval->src, INTERNAL_FUNCTION_PARAM_PASSTHRU); + php_converter_do_set_encoding(&(objval->src), INTERNAL_FUNCTION_PARAM_PASSTHRU); } /* }}} */ /* {{{ proto bool UConverter::setDestinationEncoding(string encoding) */ static PHP_METHOD(UConverter, setDestinationEncoding) { php_converter_object *objval = CONV_GET(getThis()); - php_converter_do_set_encoding(objval->dest, INTERNAL_FUNCTION_PARAM_PASSTHRU); + php_converter_do_set_encoding(&(objval->dest), INTERNAL_FUNCTION_PARAM_PASSTHRU); } /* }}} */ diff --git a/ext/intl/tests/bug75317.phpt b/ext/intl/tests/bug75317.phpt new file mode 100644 index 0000000..cbd9605 --- /dev/null +++ b/ext/intl/tests/bug75317.phpt @@ -0,0 +1,53 @@ +--TEST-- +Bug #75317 (UConverter::setDestinationEncoding changes source instead of destinatination) +--SKIPIF-- +<?php +if (!extension_loaded('intl')) die('skip intl extension is not available'); +?> +--FILE-- +<?php +$utf8 = UConverter::getAliases('utf-8')[0]; +$utf16 = UConverter::getAliases('utf-16')[0]; +$utf32 = UConverter::getAliases('utf-32')[0]; +$latin1 = UConverter::getAliases('latin1')[0]; + +function printResult($actual, $expected) { + var_dump($actual === $expected ? true : "expected: $expected, actual: $actual"); +} + +// test default values +$c = new UConverter(); +printResult($c->getDestinationEncoding(), $utf8); +printResult($c->getSourceEncoding(), $utf8); + +// test constructor args +$c = new UConverter('utf-16', 'latin1'); +printResult($c->getDestinationEncoding(), $utf16); +printResult($c->getSourceEncoding(), $latin1); + +// test setters +var_dump($c->setDestinationEncoding('utf-8')); +var_dump($c->setSourceEncoding('utf-32')); +printResult($c->getDestinationEncoding(), $utf8); +printResult($c->getSourceEncoding(), $utf32); + +// test invalid inputs dont change values +var_dump($c->setDestinationEncoding('foobar') === false); +var_dump($c->setSourceEncoding('foobar') === false); +printResult($c->getDestinationEncoding(), $utf8); +printResult($c->getSourceEncoding(), $utf32); + +?> +--EXPECT-- +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) \ No newline at end of file

« previous php.cvs (#99806) next »