fix(processors): normalize string 'true'/'false' to boolean in getProperty#16888
fix(processors): normalize string 'true'/'false' to boolean in getProperty#16888Ibochkarev wants to merge 7 commits into
Conversation
…perty JavaScript sends boolean params as strings. getProperty now converts 'true'/'false' (case-insensitive) to actual booleans so processor logic works correctly without explicit type casting.
|
I'm mildly worried this may have unintentional far-reaching consequences in processors that have been doing its own normalisation based on strings that is now going to break. |
There was a problem hiding this comment.
Pull request overview
This PR attempts to fix an issue where JavaScript/ExtJS sends boolean parameters as strings ("true"/"false") to processors, causing them to be treated as truthy strings instead of proper booleans. The solution modifies Processor::getProperty() to automatically normalize case-insensitive string "true"/"false" (with trimming) to boolean values.
Changes:
- Modified
getProperty()method inProcessor.phpto convert string "true"/"false" (case-insensitive, trimmed) to boolean - Added inline documentation explaining the normalization behavior
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
I think this suggestion makes a lot of sense given the potential impact this may have on core and extras. Copilot already highlighted a few cases in the codebase that break. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Revert getProperty() to original behavior (no boolean normalization)
- Add getBooleanProperty($k, $default) for explicit bool parsing
- Support 'true'/'false'/'on'/'off'/'1'/'0'/'yes'/'no' (case-insensitive)
- Resource/Get: use getBooleanProperty('skipFormatDates', false)
- formatDates: use !empty($resourceArray['publishedon']) for consistency
- Add ProcessorTest for getBooleanProperty() coverage
- Fix PSR12 file header spacing in Resource/Get.php
Addresses PR modxcms#16888 review (Mark-H, Copilot): avoid changing getProperty()
to prevent impact on core and extras.
|
@Mark-H please re-run review copilot. Thanks |
Code ReviewSummary Adds Assessment Clean, non-breaking addition. The Verdict: Approve |
smg6511
left a comment
There was a problem hiding this comment.
I'm of the mind that we don't need to be covering the boolean-ish values of "yes" and "on," particularly in the context of the manager backend where we have control over how boolean values are passed. With this in mind, we already have a method for dealing with typical string booleans.
Co-authored-by: Jim Graham <jim@pixelsandstrings.com>
|
@Ibochkarev - Just a heads up that since |
Ok |
|
@Ibochkarev - This one will be ready once you remove the three unneeded files, leaving just the changed |
Remove getBooleanProperty(), ProcessorTest, and phpunit.xml entry per review feedback; use existing modX::paramValueIsTrue() in Get.php instead. Fixes modxcms#14016
Done |
smg6511
left a comment
There was a problem hiding this comment.
Good, safe change after simplification and use of pre-existing method.
What does it do?
Adds a new method
Processor::getBooleanProperty($k, $default = false)that normalizes string values like"true","false","on","off","1","0","yes","no"(case-insensitive, trimmed) to boolean.Processor::getProperty()is unchanged and still returns raw values. When JavaScript sends boolean parameters to processors (e.g. via ExtJS or fetch), they arrive as strings; processors that need a real boolean can callgetBooleanProperty()so logic works without manual casting.Why is it needed?
JavaScript/ExtJS sends boolean values as strings (
"true"/"false"). Processors usinggetProperty('someFlag')receive strings, soif ($this->getProperty('someFlag'))is always truthy for non-empty strings and breaks when the intended value isfalse. Introducing a dedicatedgetBooleanProperty()avoids changing existinggetProperty()behavior (and potential impact on core and extras) while giving processors an explicit way to read boolean params.How to test
$this->getBooleanProperty('someBooleanParam', false).someBooleanParam=false(e.g. via AJAX or connector).getBooleanProperty('someBooleanParam', false)returnsfalse(boolean).someBooleanParam=trueand assert it returnstrue(boolean).someBooleanParam=TRUE,True, ortrueand assert case-insensitive, trimmed handling.someBooleanParam=on,yes,1(true) andoff,no,0(false) and assert normalization._build/test/Tests/Processors/ProcessorTest.phpfor fullgetBooleanProperty()coverage.Related issue(s)/PR(s)
Fixes #14016