Zeka Posted November 4, 2018 Share Posted November 4, 2018 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 More sharing options...
bernhard Posted November 5, 2018 Share Posted November 5, 2018 I'd consider this a bug Link to comment Share on other sites More sharing options...
dragan Posted November 5, 2018 Share Posted November 5, 2018 Same here. Did you try using a text sanitizer though? https://processwire.com/blog/posts/processwire-3.0.13-selector-upgrades-and-new-form-builder-version/#selector-engine-array-support Link to comment Share on other sites More sharing options...
BitPoet Posted November 5, 2018 Share Posted November 5, 2018 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. 1 Link to comment Share on other sites More sharing options...
Zeka Posted November 23, 2018 Author Share Posted November 23, 2018 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. 2 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now