Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a1d1269

Browse files
committed
Fix GH-17469: UConverter::transcode() not hardcoding error handling.
Respecting instead intl.use_exceptions/intl.error_level. close GH-17488
1 parent 82d71a8 commit a1d1269

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

‎NEWS‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ PHP NEWS
3333

3434
- Intl:
3535
. Fixed bug GH-11874 (intl causing segfault in docker images). (nielsdos)
36+
. Fixed bug GH-17469 (UConverter::transcode always emit E_WARNING on
37+
invalid encoding). (David Carlier)
3638

3739
- Opcache:
3840
. Fixed bug GH-17307 (Internal closure causes JIT failure). (nielsdos)

‎ext/intl/converter/converter.c‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,20 +381,23 @@ static bool php_converter_set_encoding(php_converter_object *objval,
381381
if (objval) {
382382
THROW_UFAILURE(objval, "ucnv_open", error);
383383
} else {
384-
php_error_docref(NULL, E_WARNING, "Error setting encoding: %d - %s", (int)error, u_errorName(error));
384+
char *msg;
385+
spprintf(&msg, 0, "Error setting encoding: %d - %s", (int)error, u_errorName(error));
386+
intl_error_set(NULL, error, msg, 1);
387+
efree(msg);
385388
}
386-
return 0;
389+
return false;
387390
}
388391

389392
if (objval && !php_converter_set_callbacks(objval, cnv)) {
390-
return 0;
393+
return false;
391394
}
392395

393396
if (*pcnv) {
394397
ucnv_close(*pcnv);
395398
}
396399
*pcnv = cnv;
397-
return 1;
400+
return true;
398401
}
399402
/* }}} */
400403

‎ext/intl/tests/gh17469.phpt‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
GH-17469: UConverter::transcode() raises always E_WARNING regardless of INI settings
3+
--SKIPIF--
4+
<?php
5+
if (PHP_OS_FAMILY === "Windows") die("skip currently unsupported on Windows");
6+
?>
7+
--FILE--
8+
<?php
9+
ini_set("intl.error_level", E_WARNING);
10+
ini_set("intl.use_exceptions", 0);
11+
UConverter::transcode("\x0a", 'nein!!', 'UTF-8');
12+
UConverter::transcode("\x0a", 'UTF-16BE', 'da!');
13+
14+
ini_set("intl.error_level", 0);
15+
ini_set("intl.use_exceptions", 1);
16+
17+
try {
18+
UConverter::transcode("\x0a", 'nein!!', 'UTF-8');
19+
} catch (IntlException $e) {
20+
echo $e->getMessage(), PHP_EOL;
21+
}
22+
try {
23+
UConverter::transcode("\x0a", 'UTF-16BE', 'da!');
24+
} catch (IntlException $e) {
25+
echo $e->getMessage(), PHP_EOL;
26+
}
27+
?>
28+
--EXPECTF--
29+
30+
Warning: UConverter::transcode(): Error setting encoding: 4 - U_FILE_ACCESS_ERROR in %s on line %d
31+
32+
Warning: UConverter::transcode(): Error setting encoding: 4 - U_FILE_ACCESS_ERROR in %s on line 5
33+
Error setting encoding: 4 - U_FILE_ACCESS_ERROR
34+
Error setting encoding: 4 - U_FILE_ACCESS_ERROR

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /