Jump to content

Possible​​​​​​​ bug in selectors as associative arrays?


Zeka
 Share

Recommended Posts

Hi.

I have such selector:

// selector as associative array

$selector = [
  'template' => 'diagnostic',
  'diagnostic_code%=' => '000009',
  'limit' => '20'
];

produces this (from PW debug panel):

// selector query
template=diagnostic, diagnostic_code%=9, limit=20, status<1024
// sql query 
SELECT SQL_CALC_FOUND_ROWS pages.id,pages.parent_id,pages.templates_id 
FROM `pages` 
JOIN field_diagnostic_code AS field_diagnostic_code ON field_diagnostic_code.pages_id=pages.id AND (((field_diagnostic_code.data LIKE '%9%' ) )) 
WHERE (pages.templates_id=65) 
AND (pages.status<1024) 
GROUP BY pages.id 
LIMIT 0,20

The same selector, but in string format

$selector = "template=diagnostic, diagnostic_code%=0009, limit=20";

produces this:

// selector query
template=diagnostic, diagnostic_code%=0009, limit=20, status<1024
                                                                  
// sql query
SELECT SQL_CALC_FOUND_ROWS pages.id,pages.parent_id,pages.templates_id 
FROM `pages` 
JOIN field_diagnostic_code AS field_diagnostic_code ON field_diagnostic_code.pages_id=pages.id AND (((field_diagnostic_code.data LIKE '%0009%' ) )) 
WHERE (pages.templates_id=65) 
AND (pages.status<1024) 
GROUP BY pages.id 
LIMIT 0,20

As you can see (from selector and SQL queries) it trims leading zeroes when I use the selector as an associative array.

Is it a bug or I miss something? 

Thanks, Eugene.

 

Link to comment
Share on other sites

  • 3 weeks later...
On 11/5/2018 at 8:03 PM, dragan said:

Did you try using a text sanitizer though?

@dragan Yes, didn't help. Still 

On 11/5/2018 at 3:54 PM, bernhard said:

I'd consider this a bug

@bernhard I have opened an issue https://github.com/processwire/processwire-issues/issues/743

On 11/5/2018 at 10:12 PM, BitPoet said:

The problem is that anything that looks like a ctype_digit is coerced to int in Selectors::makeSelectorArrayItem, even if you use nested array syntax and pass in the name of a sanitizer method.

@BitPoet Thanks, yes I see, there is no way to prevent conversion to int


if(is_int($value) || ctype_digit($value)) {
  $value = (int) $value;
  if($_sanitize == 'selectorValue') $_sanitize = ''; // no need to sanitize integer to string
}

Also, if you consider this as a bug, please, leave a comment on GitHub.

  • Like 2
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...