Jump to content

Selector error depending on order of selector


Jest
 Share

Recommended Posts

Hi all,

today I've run into some strange error when using selectors. The following selector works fine:

$pages->find('template=TemplateName, (many|of|different|fields*=Searching), (year=Searching), (year>=1941, year<=1960), author*=unknown, publisher*="two, maybe three words"|unknown|"another two, maybe three words", area*=All');

Whereas this one throws an error:

$pages->find('template=TemplateName, (many|of|different|fields*=Searching), (year=Searching), (year>=1941, year<=1960), author*=unknown, publisher*="two, maybe three words"|unknown, area*=All');

The only difference is in publisher field having only two values. The error is Exception: Unknown Selector operator: '' -- was your selector value properly escaped?

 Additional info:

  • ProcessWire 3.0.62
  • All values are sanitized using $sanitizer->selectorValue(string)
  • publisher value usually has commas or parenthesis
  • publisher="one, two"|"three, four" works
  • publisher="one, two"|three|"four, five" works
  • publisher="one, two"|five doesn't work
  • publisher=five works

The only conclusion I can make is the selector fails when the last value of publisher is a single word. Any thoughts?

All help is greatly appreciated!

Jan

Edited by Jest
added PW version
Link to comment
Share on other sites

I checked the behavior, and i cannot reproduce it with the following code:

$pages->find('template=project, title*="two, maybe three words"|unknown, longtext!=blubb');

 and it works like a charm... (using Dev Version: 3.0.92)

Link to comment
Share on other sites

That's interesting - your code doesn't work for me.

The same error Exception: Unknown Selector operator: '' -- was your selector value properly escaped? is shown. If I add another value to the title field (title*="two, maybe three words"|unknown|"another unknown") it works until the longtext part. There it shows an error Exception: Field does not exist: longtext. But if I remove the longtext selector and run this:

$pages->find('template=project, title*="two, maybe three words"|unknown');

It still doesn't work.

Is it possible my hosting environment is the reason for this??

Link to comment
Share on other sites

Now here's the funny thing: if I wrap the single word value in quotation marks it works.

So this doesn't work

$pages->find('template=project, title*="two, maybe three words"|unknown');

But this does work

$pages->find('template=project, title*="two, maybe three words"|"unknown"');

I've managed to make my code work by checking the number of words in a selector value and if there's only one word I wrap the value in quotation marks.

But it still bugs me why it doesn't work without quotation marks. I'll dig deeper and post the findings, if there will be any.

And thank you guys for your contributions!

Link to comment
Share on other sites

2 hours ago, Jest said:

There it shows an error Exception: Field does not exist: longtext. But if I remove the longtext selector and run this:

The Field longtext is in my dev installation ;) its just a fieldname created by me

but you can test it with the current dev Version (the dev Version will be the the Master Version in „some“ Weeks (?))

  • Thanks 1
Link to comment
Share on other sites

@zoeck Yep, I realized why the longtext is causing error... right after I posted the reply :huh: As @BitPoet stated the current dev version fixes this bug, but I'm going to stay on master 3.0.62 since the site will probably be in production sooner than the current dev will become master (and I've found the solution).

@Macrura Thanks for suggestion, the code is cleaner using the selector array but it still doesn't work - as expected due to the bug.

@BitPoet Many thanks for giving me the closure! :rolleyes: Now I'll be finally able to sleep ;)

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

×
×
  • Create New...