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

Undefined array key "-" in path_clean_string() #6834

Open
NormPlum opened this issue Jan 18, 2025 · 5 comments · May be fixed by backdrop/backdrop#4996
Open

Undefined array key "-" in path_clean_string() #6834

NormPlum opened this issue Jan 18, 2025 · 5 comments · May be fixed by backdrop/backdrop#4996

Comments

@NormPlum
Copy link

Description of the bug

The following warning message is shown in the logs when you save a node and hyphens are set to not be replaced in the URL alias patterns settings:

Warning: Undefined array key "-" in path_clean_string() (line 153 of /backdrop/core/modules/path/path.inc).

Steps To Reproduce

To reproduce the behavior:

  1. Go to Configuration > URL handling > URL aliases > URL alias patterns > URL alias pattern settings (/admin/config/urls/path/patterns/settings)
  2. Expand "Punctuation"
  3. Set "Hyphen (-)" to "No action (do not replace)" and Save configuration
  4. Edit a node (e.g. Your first post!) and Save
  5. Check the logs

Actual behavior

Warning displayed.

Expected behavior

No warning displayed.

Additional information

Add any other information that could help, such as:

  • Backdrop CMS version: 1.30.0
  • Web server and its version: Apache/2.4.62 (Debian)
  • PHP version: 8.1.31
  • Database sever (MySQL or MariaDB?) and its version: MySQL, MariaDB, or equivalent version 10.7.8-MariaDB-1:10.7.8+maria~ubu2004
@argiepiano
Copy link

argiepiano commented Jan 18, 2025

I have reproduced this issue, and submitted a PR. @NormPlum, can you check?

HOWEVER, I'm a bit hesitant about this approach. The warning happened because Backdrop tries to apply the same operation to "fancy characters" that resemble the hyphen (en and em dashes). When you select "do nothing" for hyphens, then Backdrop doesn't know what to do with en and em dashes. Fortunately, the call to transliteration_get() actually transliterates those en and em dashes to hyphens in the alias. But I'm not sure if this fix will have bad effects for other fancy characters (such as curly quotes) that are replaced with the operations done for \ and ". So, if you "do nothing" for " (regular quotes) then perhaps the curly quotes might remain in the alias, which may be bad.

So, this needs to be tested thoroughly with different scenarios.

@NormPlum
Copy link
Author

@argiepiano The PR fixes the problem (the warning's not displayed).

I'm also not sure what the best solution is but I wonder if isset() would be better than !empty(). If $cache['punctuation']['-'] is empty, it might still be worth using that. But if it's not set at all, you'll get this warning.

@argiepiano
Copy link

I think you are right - isset is better, since one of the options is to remove the character, in which case the value for that array element would be an empty string, and we don't want to skip the assignment of the fancy character in that case.

@argiepiano
Copy link

I've pushed that change. Please test...

@NormPlum
Copy link
Author

Yep, that works too - no warning displayed.

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