Skip to content

fix(processors): normalize string 'true'/'false' to boolean in getProperty#16888

Open
Ibochkarev wants to merge 7 commits into
modxcms:3.xfrom
Ibochkarev:fix/processor-boolean-property-normalization
Open

fix(processors): normalize string 'true'/'false' to boolean in getProperty#16888
Ibochkarev wants to merge 7 commits into
modxcms:3.xfrom
Ibochkarev:fix/processor-boolean-property-normalization

Conversation

@Ibochkarev

@Ibochkarev Ibochkarev commented Feb 24, 2026

Copy link
Copy Markdown
Collaborator

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 call getBooleanProperty() so logic works without manual casting.

Why is it needed?

JavaScript/ExtJS sends boolean values as strings ("true"/"false"). Processors using getProperty('someFlag') receive strings, so if ($this->getProperty('someFlag')) is always truthy for non-empty strings and breaks when the intended value is false. Introducing a dedicated getBooleanProperty() avoids changing existing getProperty() behavior (and potential impact on core and extras) while giving processors an explicit way to read boolean params.

How to test

  1. In a processor, use $this->getBooleanProperty('someBooleanParam', false).
  2. Call it with someBooleanParam=false (e.g. via AJAX or connector).
  3. Assert getBooleanProperty('someBooleanParam', false) returns false (boolean).
  4. Call with someBooleanParam=true and assert it returns true (boolean).
  5. Call with someBooleanParam=TRUE, True, or true and assert case-insensitive, trimmed handling.
  6. Call with someBooleanParam=on, yes, 1 (true) and off, no, 0 (false) and assert normalization.
  7. Run _build/test/Tests/Processors/ProcessorTest.php for full getBooleanProperty() coverage.

Related issue(s)/PR(s)

Fixes #14016

…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.
@Ibochkarev Ibochkarev marked this pull request as ready for review February 24, 2026 17:49
@Mark-H Mark-H requested a review from Copilot February 24, 2026 23:16
@Mark-H

Mark-H commented Feb 24, 2026

Copy link
Copy Markdown
Collaborator

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 in Processor.php to 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.

Comment thread core/src/Revolution/Processors/Processor.php Outdated
Comment thread core/src/Revolution/Processors/Processor.php Outdated
Comment thread core/src/Revolution/Processors/Processor.php Outdated
Comment thread core/src/Revolution/Processors/Processor.php Outdated
Comment thread core/src/Revolution/Processors/Processor.php Outdated
Comment thread core/src/Revolution/Processors/Processor.php Outdated
Comment thread core/src/Revolution/Processors/Processor.php Outdated
@Mark-H

Mark-H commented Feb 24, 2026

Copy link
Copy Markdown
Collaborator

Introduce a new method like getBooleanProperty() that performs normalization

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.

Ibochkarev and others added 4 commits February 25, 2026 10:16
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.
@Ibochkarev

Copy link
Copy Markdown
Collaborator Author

@Mark-H please re-run review copilot. Thanks

@biz87

biz87 commented Feb 25, 2026

Copy link
Copy Markdown

Code Review

Summary

Adds Processor::getBooleanProperty($k, $default) to normalize string boolean values ("true", "false", "on", "off", "1", "0", "yes", "no") to proper PHP booleans. Existing getProperty() is unchanged. Includes comprehensive PHPUnit tests covering all edge cases (case insensitivity, trimming, native booleans, missing keys, unknown strings).

Assessment

Clean, non-breaking addition. The match expression (PHP 8.0+) is appropriate for the project's PHP 8.1+ requirement. Test coverage is thorough — 13 test methods covering all branches. The method properly falls through to $default for unrecognized strings and empty values, which is the correct behavior. No existing code is modified beyond adding the new method and test file.

Verdict: Approve

@smg6511 smg6511 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread core/src/Revolution/Processors/Resource/Get.php Outdated
Co-authored-by: Jim Graham <jim@pixelsandstrings.com>
@smg6511

smg6511 commented May 20, 2026

Copy link
Copy Markdown
Collaborator

@Ibochkarev - Just a heads up that since getBooleanProperty isn't needed you can drop the method and its associated unit tests.

@Ibochkarev

Copy link
Copy Markdown
Collaborator Author

@Ibochkarev - Just a heads up that since getBooleanProperty isn't needed you can drop the method and its associated unit tests.

Ok

@smg6511

smg6511 commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

@Ibochkarev - This one will be ready once you remove the three unneeded files, leaving just the changed Get.php.

Remove getBooleanProperty(), ProcessorTest, and phpunit.xml entry per
review feedback; use existing modX::paramValueIsTrue() in Get.php instead.

Fixes modxcms#14016
@Ibochkarev

Copy link
Copy Markdown
Collaborator Author

@Ibochkarev - This one will be ready once you remove the three unneeded files, leaving just the changed Get.php.

Done

@Ibochkarev Ibochkarev requested a review from smg6511 June 19, 2026 17:08

@smg6511 smg6511 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good, safe change after simplification and use of pre-existing method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Processors do not respect type of the parameter that was passed from javascript code

5 participants