Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the deprecation problem of idn_to_ascii() since php7.2 #1505

Merged
merged 1 commit into from
Apr 29, 2021

Conversation

amiriun
Copy link

@amiriun amiriun commented Mar 22, 2021

idn_to_ascii() php function is deprecated as of php 7.2
However it is still available but you should use INTL_IDNA_VARIANT_UTS46 as a third argument. (see https://www.php.net/manual/en/function.idn-to-ascii.php)
Otherwise you will see the error because INTL_IDNA_VARIANT_2003 is deprecated.
image

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All automated tests passed successfully (all builds are green)

@amiriun amiriun changed the title Fix the deprecation problem of idn_to_ascii since php7.2 Fix the deprecation problem of idn_to_ascii() since php7.2 Mar 22, 2021
@kiatng
Copy link
Contributor

kiatng commented Mar 23, 2021

There are 4 references to idn_to_ascii that may require attention, see search result.

See also similar issues in M2 raised in stackoverflow and in github.

@Flyingmana Flyingmana merged commit 0412ad6 into OpenMage:1.9.4.x Apr 29, 2021
@github-actions
Copy link

Unit Test Results

1 files  ±0  1 suites  ±0   0s ⏱️ ±0s
0 tests ±0  0 ✔️ ±0  0 💤 ±0  0 ❌ ±0 
2 runs  ±0  2 ✔️ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit 0412ad6. ± Comparison against base commit 57563fc.

@luigifab
Copy link
Contributor

luigifab commented Dec 1, 2021

I getting the same error with PHP 7.3.33 when I try to update base url from backend.

Deprecated functionality: idn_to_ascii(): INTL_IDNA_VARIANT_2003 is deprecated
  in app/code/core/Mage/Core/Helper/Url.php on line 183

😏

Same fix:

diff --git a/web/app/code/core/Mage/Core/Helper/Url.php b/web/app/code/core/Mage/Core/Helper/Url.php
index 4b2f512e72..05f37332c6 100644
--- a/web/app/code/core/Mage/Core/Helper/Url.php
+++ b/web/app/code/core/Mage/Core/Helper/Url.php
@@ -180,9 +180,13 @@ class Mage_Core_Helper_Url extends Mage_Core_Helper_Abstract
         $parsedUrl = parse_url($url);
         if (!$this->_isPunycode($parsedUrl['host'])) {
             if (function_exists('idn_to_ascii')) {
-                $host = idn_to_ascii($parsedUrl['host']);
+                if (defined('IDNA_NONTRANSITIONAL_TO_ASCII') && defined('INTL_IDNA_VARIANT_UTS46')) {
+                    $host = idn_to_ascii($parsedUrl['host'], IDNA_NONTRANSITIONAL_TO_ASCII, INTL_IDNA_VARIANT_UTS46);
+                } else {
+                    $host = idn_to_ascii($parsedUrl['host']);
+                }
             } else {
-                $idn = new Net_IDNA2();
+                $idn  = new Net_IDNA2();
                 $host = $idn->encode($parsedUrl['host']);
             }
             return str_replace($parsedUrl['host'], $host, $url);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants