Jump to content

escape commas in selector


froot
 Share

Recommended Posts

I have an issue with selectors, whenever there is a comma in the selected value…

$foo = $item->foo; // "what, ever, with, commas"
$bar = pages()->get("template=foo_template, title=$foo");

then I get 

Fehler: Exception: Unknown Selector operator: '[empty]' -- was your selector value properly escaped? (in wire/core/Selectors.php line 222)

Because it thinks that what ever is after the comma is the next selector.

Though the value in question is not expected to have commas, this shouldn't happen. How can I escape it properly?

And then, also, even though I'm NOT in config debug mode, Tracy Debugger is NOT active and I am NOT logged in, i.e. not superuser, I still get the error in the frontend, breaking the entire output script, showing me no CSS (I use markup regions). That's of course not a good user experience. Shouldn't it show a white page instead? Do I have to use a try-catch code block?
 

Link to comment
Share on other sites

I tried that. First of all, I don't see utf8mb4 in the list of charsets, as suggested in the stackOverflow answers, so I cannot select it.

Then, trying to change the collation to utf8mb4_unicode_ci or utf8mb4_german2_ci doesn't help, I think it requires the charset to be set to utf8mb4 as well. If I check "Change all tables collations" and "Change all tables columns collations" I get an error like so

image.png.1edfabe57bd477f374c3a16504d045e9.png

The behaviour in the frontend of my project doesn't change anyway.

I'm not very knowledgeable in that area  anyway, so thanks for help!

Link to comment
Share on other sites

 

6 hours ago, fruid said:

First of all, I don't see utf8mb4 in the list of charsets

What is your MySQL version? utf8mb4 support started with version 5.5.

This query will list all available charsets:

SHOW CHARACTER SET;

 

Link to comment
Share on other sites

I cannot find the MySQL version. It's not in the database settings in the host and there's no Database server widget when I click on the home icon in phpMyAdmin and also I do not have SSH access. Something so simple, so far…

Link to comment
Share on other sites

3 minutes ago, fruid said:

I cannot find the MySQL version. It's not in the database settings in the host and there's no Database server widget when I click on the home icon in phpMyAdmin and also I do not have SSH access. Something so simple, so far…

In phpMyAdmin click on the Home icon. Now click on the tab "SQL" and insert "SHOW CHARACTER SET;" into the query editor. Now click GO in the bottom right. This should give you a list of available charsets like

787386207_2022-12-01-182129.thumb.png.54edb25179c3d40ccfd870c304a54eba.png
 

Link to comment
Share on other sites

yes it is in the list. Actually I don't know anymore where to set the CharSet at all (let alone that I didn't find utf8mb4 in the list). I think mixed it up with the dropdown in the import tab. So how to set the CharSet to begin with? And then, I thought I changed the collation for one specific database but it seems like that's a setting that applies to the whole server? Not good…

Link to comment
Share on other sites

1 minute ago, fruid said:

yes it is in the list. Actually I don't know anymore where to set the CharSet at all (let alone that I didn't find utf8mb4 in the list). I think mixed it up with the dropdown in the import tab. So how to set the CharSet to begin with? And then, I thought I changed the collation for one specific database but it seems like that's a setting that applies to the whole server? Not good…

You can set the collation per database. See here: https://dev.mysql.com/doc/refman/8.0/en/charset-database.html 

You can run this query for a database to see current charset and collation:

USE db_name;
SELECT @@character_set_database, @@collation_database;

You can run this query for a database to change charset and collation:

ALTER DATABASE db_name
    CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci

 

  • Like 1
Link to comment
Share on other sites

Don't think this is DB related then.
Umlauts in sanitized selector value are not breaking the selector in my case

$val = $sanitizer->selectorValue("äöü");
db($pages->find("title=$val")); 
// results in:
// ProcessWire\PageArray
// count: 0
// items: array (0)
// selectors: 'title="äöü"'
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...