php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75317 UConverter::setDestinationEncoding changes source instead of destinatination
Submitted: 2017-10-05 13:24 UTC Modified: -
From: fabien dot villepinte at gmail dot com Assigned:
Status: Closed Package: intl (PECL)
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2017-10-05 13:24 UTC] fabien dot villepinte at gmail dot com
Description:
------------
While I was writing tests to improve test coverage I've found an error with UConverter::setDestinationEncoding ( http://php.net/manual/fr/uconverter.setdestinationencoding.php ).

setDestinationEncoding() changes the source encoding instead of the destination encoding.

Test script:
---------------
<?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);

Expected result:
----------------
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)

Actual result:
--------------
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
string(31) "expected: UTF-8, actual: UTF-16"
bool(true)
bool(true)
bool(true)
string(31) "expected: UTF-8, actual: UTF-16"
bool(true)

Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-10-09 14:29 UTC] andrew dot nester dot dev at gmail dot com
Thanks for reporting the issue!

Just send PR fixing this
 [2017-10-09 14:30 UTC] andrew dot nester dot dev at gmail dot com
Sorry, I meant I've just sent PR fixing this :)
 [2017-10-19 11:04 UTC] krakjoe@php.net
Automatic comment on behalf of andrew.nester.dev@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=80c3b078b8f4da054d95bc35b7951bb3f6987b5d
Log: Fixed #75317 - UConverter::setDestinationEncoding changes source instead of destinatination
 [2017-10-19 11:04 UTC] krakjoe@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 08:01:29 2024 UTC