Jump to content

Fatal error when $config->pageNameWhitelist leave blank and $config->pageNameCharset = UTF8 if use non ASCII characters in page name


Recommended Posts

Posted

Hi all,

SYMPTOM

When creating or editing a page with Chinese characters in the page name
(e.g., 關於我們) while $config->pageNameCharset = "UTF8" and
$config->pageNameWhitelist = "" (empty), a fatal error occurs:

Fatal Error: Uncaught ValueError: idn_to_ascii(): Argument #1 ($domain)
must not be empty in Sanitizer.php:1138

Environment

PHP 8.4
ProcessWire 2.6.260

I create an bug report in github

https://github.com/processwire/processwire-issues/issues/2215

By the help of AI, I found the root cause.

1. The pageNameHasConflict() method in PagesNames.php calls
   $sanitizer->pageName($name, Sanitizer::toAscii) to convert the UTF-8
   name to ASCII for duplicate name checking.

2. Sanitizer::pageName() triggers punyEncodeName() to encode the Chinese
   characters using Punycode.

3. Inside punyEncodeName() (line 1085), when $version > 1, each character
   of the name is checked against $config->pageNameWhitelist.

4. When pageNameWhitelist is empty (""), every Chinese character fails
   the whitelist check and gets replaced with "-" (hyphen).

5. After collapsing consecutive hyphens and trimming leading/trailing
   hyphens, the result is an EMPTY STRING "".

6. The empty string is then passed to PHP's idn_to_ascii() function
   (line 1158), which throws ValueError because it requires a non-empty
   $domain argument.

Gideon

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   1 member

×
×
  • Create New...