ezyang / htmlpurifier

Standards compliant HTML filter written in PHP
http://htmlpurifier.org
GNU Lesser General Public License v2.1
3.08k stars 327 forks source link

idn_to_ascii(): INTL_IDNA_VARIANT_2003 is deprecated #163

Open aaronpk opened 6 years ago

aaronpk commented 6 years ago

I'm getting this bizarre error in some cases under PHP 7.2. Apparently the idn_to_ascii function deprecated the INTL_IDNA_VARIANT_2003 variant in PHP 7.2, and you're supposed to use INTL_IDNA_VARIANT_UTS46 instead now. However, PHP seems to be still using INTL_IDNA_VARIANT_2003 as the default if none is specified. This ends up causing an exception.

I think this is wrong behavior of PHP, but it would be easier to fix in this library calling the idn_to_ascii function. I've patched my running instance to call idn_to_ascii($string,0,INTL_IDNA_VARIANT_UTS46) already.

Has anyone else encountered this issue?

aaronpk commented 6 years ago

Did a little digging and it looks like this was already fixed in master! https://github.com/ezyang/htmlpurifier/pull/148 Looking forward to the next release! 🎉

anupammo commented 5 years ago

think there's a better way to sort out that issue. As we all know that email library not supported in php 7.2 and that's why error occured.

Quick Solution :

  1. Go to cPanel
  2. Select PHP version
  3. change it to 7.1 instead of 7.2
shafique-uddin commented 5 years ago

think there's a better way to sort out that issue. As we all know that email library not supported in php 7.2 and that's why error occured.

Quick Solution :

  1. Go to cPanel
  2. Select PHP version
  3. change it to 7.1 instead of 7.2

It's an easy way to solve this problem in a second.

benjaminkohl commented 5 years ago

So what is the real solution to this? I am experiencing this error with version 4.11.0 in PHP 7.2 and I don't consider rolling back to PHP 7.1 to be a reasonable solution. Is PHP to blame for how this function is being called? It looks like symfony/polyfill is defining that constant. Maybe it shouldn't be?

benjaminkohl commented 5 years ago

To avoid this issue in PHP 7.2, apparently two constants need to be defined but whose responsibility is that and what are the values supposed to be? I'm really surprised the PHP devs decided to deprecate that constant yet leave it as the default value for the third parameter of idn_to_ascii(). This screenshot is from the offending block of code in this library's Host.php file. Screen Shot 2019-09-17 at 1 41 55 PM

ezyang commented 5 years ago

@benjaminkohl Can you file a new bug for this?

jaygilmore commented 3 years ago

Was this satisfactorily resolved? I'm seeing errors similar to this in an app where this library is a dependency (Freescout): I'm seeing the following error on PHP 7.2 and above:

idn_to_ascii(): INTL_IDNA_VARIANT_2003 is deprecated (View: www/resources/views/conversations/partials/thread.blade.php) (View: www/resources/views/conversations/partials/thread.blade.php) (View: www/resources/views/conversations/partials/thread.blade.php) {"userId":1,"email":"jay@modx.com","exception":"[object] (ErrorException(code: 0): idn_to_ascii(): INTL_IDNA_VARIANT_2003 is deprecated (View: www/resources/views/conversations/partials/thread.blade.php) (View: www/resources/views/conversations/partials/thread.blade.php) (View: www/resources/views/conversations/partials/thread.blade.php) at www/vendor/ezyang/htmlpurifier/library/HTMLPurifier/AttrDef/URI/Host.php:103, ErrorException(code: 0): idn_to_ascii(): INTL_IDNA_VARIANT_2003 is deprecated (View: www/resources/views/conversations/partials/thread.blade.php) (View: www/resources/views/conversations/partials/thread.blade.php) at www/vendor/ezyang/htmlpurifier/library/HTMLPurifier/AttrDef/URI/Host.php:103, ErrorException(code: 0): idn_to_ascii(): INTL_IDNA_VARIANT_2003 is deprecated (View: www/resources/views/conversations/partials/thread.blade.php) at www/vendor/ezyang/htmlpurifier/library/HTMLPurifier/AttrDef/URI/Host.php:103, ErrorException(code: 0): idn_to_ascii(): INTL_IDNA_VARIANT_2003 is deprecated at www/vendor/ezyang/htmlpurifier/library/HTMLPurifier/AttrDef/URI/Host.php:103)

I'm not sure if this is a new issue or if I'm supposed to do something to get this to work reliably?

Web Server: nginx/1.16.1 PHP: PHP 7.3.11 OS: centOS6

Any help or guidance would be appreciated.

ezyang commented 3 years ago

did freescout update to a newer version? :)

jaygilmore commented 3 years ago

The version used is 4.12, so, the PHP7.2+ compatibility should be fine according to your docs. That said, they completely dismissed the issue out of hand stating that the deprecation notice and the simultaneous 500 error that occurs are not related. While I agree that something that throws a deprecation notice isn't the specific culprit of the 500, the 500 still occurs and still stops the application from working when the notice is logged at PHP 7.2+. Thoughts?

ezyang commented 3 years ago

in 4.12 there is not supposed to be any occurrence of INTL_IDNA_VARIANT_2003. Can you grep in Freescout and see where the string INTL_IDNA_VARIANT_2003 occurs?

freescout-helpdesk commented 3 years ago

Error occurs here on PHP7.3: https://github.com/ezyang/htmlpurifier/blob/master/library/HTMLPurifier/AttrDef/URI/Host.php#L103

freescout-helpdesk commented 3 years ago

The only way to fix this seems to be:


            try {
                if (defined('IDNA_NONTRANSITIONAL_TO_ASCII') && defined('INTL_IDNA_VARIANT_UTS46')) {
                    $string = idn_to_ascii($string, IDNA_NONTRANSITIONAL_TO_ASCII, INTL_IDNA_VARIANT_UTS46);
                } else {
                    $string = idn_to_ascii($string);
                }
            } catch (\Exception $e) {

            }
freescout-helpdesk commented 3 years ago

Is it ok to create a pull request for this https://github.com/ezyang/htmlpurifier/issues/163#issuecomment-886888844? PHP developers made a mistake for which there is no other solutions.

bytestream commented 3 years ago

We need a reproducer and https://github.com/ezyang/htmlpurifier/issues/163#issuecomment-886888844 isn't a valid fix

Did you check phpinfo() for the libicu version on the system that's producing the error?