Remove deprecated INTL_IDNA_VARIANT_2003

Cf. <https://wiki.php.net/rfc/deprecate-and-remove-intl_idna_variant_2003>
This commit is contained in:
Christoph M. Becker 2019-01-28 15:18:01 +01:00
parent e973663882
commit 3d15a6f86b
4 changed files with 16 additions and 110 deletions

3
NEWS
View File

@ -9,4 +9,7 @@ PHP NEWS
. Removed deprecated image2wbmp(). (cmb)
. Removed deprecated png2wbmp() and jpeg2wbmp(). (cmb)
- Intl:
. Removed deprecated INTL_IDNA_VARIANT_2003. (cmb)
<<< NOTE: Insert NEWS from last stable release here prior to actual release! >>>

View File

@ -29,6 +29,10 @@ PHP 8.0 UPGRADE NOTES
. The deprecated functions png2wbmp() and jpeg2wbmp() have been removed.
RFC: https://wiki.php.net/rfc/deprecate-png-jpeg-2wbmp
- Intl:
. The deprecated constant INTL_IDNA_VARIANT_2003 has been removed.
RFC: https://wiki.php.net/rfc/deprecate-and-remove-intl_idna_variant_2003
========================================
2. New Features
========================================

View File

@ -33,8 +33,7 @@
/* }}} */
enum {
INTL_IDN_VARIANT_2003 = 0,
INTL_IDN_VARIANT_UTS46
INTL_IDN_VARIANT_UTS46 = 1
};
/* {{{ grapheme_register_constants
@ -73,7 +72,6 @@ void idn_register_constants( INIT_FUNC_ARGS )
REGISTER_LONG_CONSTANT("IDNA_NONTRANSITIONAL_TO_UNICODE", UIDNA_NONTRANSITIONAL_TO_UNICODE, CONST_CS | CONST_PERSISTENT);
/* VARIANTS */
REGISTER_LONG_CONSTANT("INTL_IDNA_VARIANT_2003", INTL_IDN_VARIANT_2003, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("INTL_IDNA_VARIANT_UTS46", INTL_IDN_VARIANT_UTS46, CONST_CS | CONST_PERSISTENT);
/* PINFO ERROR CODES */
@ -176,85 +174,11 @@ static void php_intl_idn_to_46(INTERNAL_FUNCTION_PARAMETERS,
uidna_close(uts46);
}
static void php_intl_idn_to(INTERNAL_FUNCTION_PARAMETERS,
const zend_string *domain, uint32_t option, int mode)
{
UChar* ustring = NULL;
int ustring_len = 0;
UErrorCode status;
zend_string *u8str;
/* convert the string to UTF-16. */
status = U_ZERO_ERROR;
intl_convert_utf8_to_utf16(&ustring, &ustring_len, ZSTR_VAL(domain), ZSTR_LEN(domain), &status);
if (U_FAILURE(status)) {
intl_error_set_code(NULL, status);
/* Set error messages. */
intl_error_set_custom_msg( NULL, "Error converting input string to UTF-16", 0 );
if (ustring) {
efree(ustring);
}
RETURN_FALSE;
} else {
UChar converted[MAXPATHLEN];
int32_t converted_ret_len;
status = U_ZERO_ERROR;
#if U_ICU_VERSION_MAJOR_NUM >= 55
UIDNAInfo info = UIDNA_INFO_INITIALIZER;
UIDNA *idna = uidna_openUTS46((int32_t)option, &status);
if (U_FAILURE(status)) {
intl_error_set( NULL, status, "idn_to_ascii: failed to create an UIDNA instance", 0 );
RETURN_FALSE;
}
if (mode == INTL_IDN_TO_ASCII) {
converted_ret_len = uidna_nameToASCII(idna, ustring, ustring_len, converted, MAXPATHLEN, &info, &status);
} else {
converted_ret_len = uidna_nameToUnicode(idna, ustring, ustring_len, converted, MAXPATHLEN, &info, &status);
}
uidna_close(idna);
#else
UParseError parse_error;
if (mode == INTL_IDN_TO_ASCII) {
converted_ret_len = uidna_IDNToASCII(ustring, ustring_len, converted, MAXPATHLEN, (int32_t)option, &parse_error, &status);
} else {
converted_ret_len = uidna_IDNToUnicode(ustring, ustring_len, converted, MAXPATHLEN, (int32_t)option, &parse_error, &status);
}
#endif
efree(ustring);
if (U_FAILURE(status)) {
intl_error_set( NULL, status, "idn_to_ascii: cannot convert to ASCII", 0 );
RETURN_FALSE;
}
status = U_ZERO_ERROR;
u8str = intl_convert_utf16_to_utf8(converted, converted_ret_len, &status);
if (!u8str) {
/* Set global error code. */
intl_error_set_code(NULL, status);
/* Set error messages. */
intl_error_set_custom_msg( NULL, "Error converting output string to UTF-8", 0 );
RETURN_FALSE;
}
}
/* return the allocated string, not a duplicate */
RETVAL_NEW_STR(u8str);
}
static void php_intl_idn_handoff(INTERNAL_FUNCTION_PARAMETERS, int mode)
{
zend_string *domain;
zend_long option = 0,
variant = INTL_IDN_VARIANT_UTS46;
variant = INTL_IDN_VARIANT_UTS46;
zval *idna_info = NULL;
intl_error_reset(NULL);
@ -265,9 +189,8 @@ static void php_intl_idn_handoff(INTERNAL_FUNCTION_PARAMETERS, int mode)
RETURN_NULL(); /* don't set FALSE because that's not the way it was before... */
}
if (variant != INTL_IDN_VARIANT_2003 && variant != INTL_IDN_VARIANT_UTS46) {
php_intl_bad_args("invalid variant, must be one of {"
"INTL_IDNA_VARIANT_2003, INTL_IDNA_VARIANT_UTS46}");
if (variant != INTL_IDN_VARIANT_UTS46) {
php_intl_bad_args("invalid variant, must be INTL_IDNA_VARIANT_UTS46");
RETURN_FALSE;
}
@ -281,29 +204,14 @@ static void php_intl_idn_handoff(INTERNAL_FUNCTION_PARAMETERS, int mode)
}
/* don't check options; it wasn't checked before */
if (variant == INTL_IDN_VARIANT_2003) {
php_error_docref(NULL, E_DEPRECATED, "INTL_IDNA_VARIANT_2003 is deprecated");
}
if (idna_info != NULL) {
if (variant == INTL_IDN_VARIANT_2003) {
php_error_docref0(NULL, E_NOTICE,
"4 arguments were provided, but INTL_IDNA_VARIANT_2003 only "
"takes 3 - extra argument ignored");
} else {
idna_info = zend_try_array_init(idna_info);
if (!idna_info) {
return;
}
idna_info = zend_try_array_init(idna_info);
if (!idna_info) {
return;
}
}
if (variant == INTL_IDN_VARIANT_2003) {
php_intl_idn_to(INTERNAL_FUNCTION_PARAM_PASSTHRU, domain, (uint32_t)option, mode);
}
else {
php_intl_idn_to_46(INTERNAL_FUNCTION_PARAM_PASSTHRU, domain, (uint32_t)option, mode, idna_info);
}
php_intl_idn_to_46(INTERNAL_FUNCTION_PARAM_PASSTHRU, domain, (uint32_t)option, mode, idna_info);
}
/* {{{ proto string idn_to_ascii(string domain[, int options[, int variant[, array &idna_info]]])

View File

@ -21,9 +21,6 @@ var_dump(idn_to_ascii("", 0, INTL_IDNA_VARIANT_UTS46 + 10));
echo "empty domain:", "\n";
var_dump(idn_to_ascii("", 0, INTL_IDNA_VARIANT_UTS46));
echo "fourth arg for 2003 variant (only notice raised):", "\n";
var_dump(idn_to_ascii("foo.com", 0, INTL_IDNA_VARIANT_2003, $foo));
echo "with error, but no details arg:", "\n";
var_dump(idn_to_ascii("www.fußball.com-", 0, INTL_IDNA_VARIANT_UTS46));
@ -54,18 +51,12 @@ Warning: idn_to_ascii(): idn_to_ascii: bad arguments in %s on line %d
NULL
bad variant:
Warning: idn_to_ascii(): idn_to_ascii: invalid variant, must be one of {INTL_IDNA_VARIANT_2003, INTL_IDNA_VARIANT_UTS46} in %s on line %d
Warning: idn_to_ascii(): idn_to_ascii: invalid variant, must be INTL_IDNA_VARIANT_UTS46 in %s on line %d
bool(false)
empty domain:
Warning: idn_to_ascii(): idn_to_ascii: empty domain name in %s on line %d
bool(false)
fourth arg for 2003 variant (only notice raised):
Deprecated: idn_to_ascii(): INTL_IDNA_VARIANT_2003 is deprecated in %s on line %d
Notice: idn_to_ascii(): 4 arguments were provided, but INTL_IDNA_VARIANT_2003 only takes 3 - extra argument ignored in %s on line %d
string(7) "foo.com"
with error, but no details arg:
bool(false)
with error, with details arg: