Jump to content

What are the rules for the comma character (,) in selectors?


Recommended Posts


I'm trying to build a search function using selectors but when "sanitizing" a string, containing a comma, with Sanitizer::selectorValue it sometimes removes the comma. Here are some test runs (first row is input, second is selectorValue output) :



,test, '
"test '"



guns n' roses, mötley crüe
"guns n' roses mötley crüe"




test, test2
"test, test2"

Also in the documentation for selectorValue it says:

Replaces disallowed characters with spaces

does this mean you can't search for all characters (comma)?

  • Like 1
Link to comment
Share on other sites

MySQL's fulltext indexes don't index commas. As you saw, commas and quotes will get trimmed from the front and back of the string. The sanitizer leaves single quote characters by themselves just in case they are an apostrophe. The sanitizer is fast but not smart here, which is why you saw it leave [what it thinks] is an apostrophe at the beginning of a couple of your tests.

A comma in the middle of the string is fine. It'll be ignored by the fulltext index, but could still be used for an exact match '=' operation. I'm not certain why it's removing the comma from your guns n roses string, but looks like a bug to me. Apparently it doesn't like the combination of apostrophe and comma, because the string works fine as soon as I remove the "n'" part of it. I will use that to test and debug -- thanks.

Link to comment
Share on other sites

The behavior you see here where sometimes it allows commas and sometimes it doesn't is because it depends on what other characters are in the strong. So it'll let a comma stay in "test, test2" but not "guns n' roses, mötley crüe". It's a little too strict, and this function could be a lot smarter, so I'm working on some updates to it that I'll post later this week.

  • Like 1
Link to comment
Share on other sites

  • 11 months later...

Was this issue ever resolved?  The code below will fail when given the string "well, I":

$query = $sanitizer->selectorValue($input->get->q);

$this_results = $pages->find("template=item, body|title|artists.title%=$query, sort=-posted, limit=10");

The error output:

Error Exception: Unknown Selector operator: '' -- was your selector value properly escaped? (in /home/public_html/wire/core/Selectors.php line 165)

#0 /home/public_html/wire/core/Selectors.php(190): Selectors->create('I', '', '')
#1 /home/public_html/wire/core/Selectors.php(63): Selectors->extractString('template=item, ...')
#2 /home/public_html/wire/core/Pages.php(132): Selectors->__construct('template=item, ...')
#3 /home/public_html/wire/core/Wire.php(269): Pages->___find('template=item, ...')
#4 /home/public_html/wire/core/Wire.php(229): Wire->runHooks(Array, Array)
#5 /home/public_html/site/templates/section.php(92): Wire->__call('find', Array)
#6 /home/public_html/site/templates/section.php(92): Pages->find('find', Array)
#7 /home/public_html/site/templates/home.php(78): include('/home/msvalerie...')

I'm using PW 2.2.2.

Nevermind, disregard -- editing the wrong template.  How embarassing...!

  • Like 1
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Similar Content

    • By Falk
      Hi Forum!
      I have the following content in a ckeditor body-field:
      <figure class="align_right"><img alt="some random alt text" src="path/to/image-file" /> <figcaption>some random caption text</figcaption> </figure> <p>some random text</p> I use 
      $text = $sanitizer->truncate($page->body, [ 'type' => 'sentence', 'maxLength' => 400, 'visible' => true ]); $content = "<p>"; $content .= $text; $content .= "</p>"; echo $content; to output the body-field in my template, which results in…
      <p>some random caption text some random text</p>
      Is there any way to tell $sanitizer->truncate to skip/remove/ignore anything that’s inside a <figure> Tag, so that I get rid of the part "some random caption text"?
    • By Robin S
      Sanitizer EasySlugger
      Allows the use of the EasySlugger library as Sanitizer methods.
      Install the Sanitizer EasySlugger module.
      The module adds four new sanitizer methods.
      slugger($string, $options)
      Similar to $sanitizer->pageName() - I'm not sure if there are any advantages over that method. Included because it is one of the methods offered by EasySlugger.
      $slug = $sanitizer->slugger('Lorem Ipsum'); // Result: lorem-ipsum utf8Slugger($string, $options)
      Creates slugs from non-latin alphabets.
      $slug = $sanitizer->utf8Slugger('这个用汉语怎么说'); // Result: zhe-ge-yong-han-yu-zen-me-shuo seoSlugger($string, $options)
      Augments the string before turning it into a slug. The conversions are related to numbers, currencies, email addresses and other common symbols.
      $slug = $sanitizer->seoSlugger('The price is $5.99'); // Result: the-price-is-5-dollars-99-cents See the EasySlugger readme for some more examples.
      seoUtf8Slugger($string, $options)
      A combination of utf8Slugger() and seoSlugger().
      $slug = $sanitizer->seoUtf8Slugger('价钱是 $5.99'); // Result: jia-qian-shi-5-dollars-99-cents $options argument
      Each of the methods can take an $options array as a second argument.
      separator (string): the character that separates words in the slug. Default: - unique (bool): Determines whether a random suffix is added at the end of the slug. Default: false $slug = $sanitizer->utf8Slugger('这个用汉语怎么说', ['separator' => '_', 'unique' => true]); // Result: zhe_ge_yong_han_yu_zen_me_shuo_3ad66c4  
    • By VeiJari
      Hello forum!
      I've yet again stumbled on a head-scratching situation. We have enabled the option on our articles template and events template that it skips the title adding part and goes straight to the form. This is what our customer wants. So when you add a new article or event it automatically names it temporary to "article-0000000" and same with event. Now the problem is that obviously after saving the form we want to change to page url or "name" to the title, like it's normally. 
      Now here's the code for the hook:
      wire()->addHookBefore("Pages::saved(template=tapahtuma|artikkeli)", function($hook) {
        $page = $hook->arguments(0);
        $newUrl = wire()->sanitizer->pageName($page->title); // give it a name used in the url for the page
        $page->setAndSave('name', $newUrl);
      I get the correct page and the name and path changes when I log them, but when I try to save it. It just loads and then I get: 
      Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 262144 bytes) This happens in sanitizer.php
      and then another error: Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 262144 bytes) in Unknown on line 0
      What is happening? Am I not suppose to use sanitizer in this way? When we made a temporary page object in out other hook, the sanitizer worked perfectly.
      Thanks for the help!
    • By Robin S
      A community member raised a question and I thought a new sanitizer method for the purpose would be useful, hence...
      Sanitizer Transliterate
      Adds a transliterate method to $sanitizer that performs character replacements as defined in the module config. The default character replacements are based on the defaults from InputfieldPageName, but with uppercase characters included too.
      Install the Sanitizer Transliterate module.
      Customise the character replacements in the module config as needed.
      Use the sanitizer on strings like so:
      $transliterated_string = $sanitizer->transliterate($string);
    • By Noel Boss
      To create a new gitlab issue, I'd like to send an Email to the following email address using FormBuilder: 
      unfortunately, the / in the email gets striped by the sanitizer:
      wire('sanitizer')->email(incoming+account/repository@incoming.gitlab.com'); // output: incoming+accountrepository@incoming.gitlab.com Is there any way to configure the sanitizer? Any other Ideas how to send the mail to this address?
      Ps.: I can not define the email format as it is defined by gitlab. The format is also kind of "common" and known as email-alias in the form of emailaccount+alias@domain.com – gmail uses it to label mails…
  • Create New...