Repository navigation
Trim whitespace at either end of a condition value - #62
Merged
Merged
Conversation
#60 stored condition values as typed, which stopped trimming them. A space nobody can see is almost always pasted by accident, and it fails silently in the worst direction: a block rule on "/wp-admin " matches nothing. Trimmed in the validator, so the screen, an import and WP-CLI all get it, as WordPress's sanitiser did before. Whitespace inside a value is kept; a regex can still match a leading or trailing space.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #61 (#60). Storing condition values as typed also stopped trimming them. Before #60, WordPress's sanitiser trimmed every value, so this restores that one piece of the old behaviour and keeps everything else #60 fixed.
Why trim: a space nobody can see is almost always pasted by accident, and it fails silently in the worst direction. A block rule on
/wp-admin(starts_with,equals,ends_with) matches nothing, and nothing says so. That's a fail-open no Site Health check can catch.Condition_Rule_Type_Base::validate_settings()trims leading and trailing whitespace after removing control characters. Because it's the validator, the rule screen, an import and WP-CLI all get it.a b), and everything Saving a rule strips < and percent-encodings from condition values #60 fixed (<,%xx, entities, quotes) is still stored as typed.\sor\x20is visible.Testing
New
ConditionValueRoundTripTest::test_whitespace_at_either_end_is_trimmed:" /wp-admin \t "is stored as/wp-admin;a bis kept.Unit: 326 tests pass.
Integration: 640 tests pass. The only warnings are the existing two about the local short
DB_PASSWORD.Static checks:
composer lintandcomposer analyseare clean.CHANGELOG: the Saving a rule strips < and percent-encodings from condition values #60 entry under
[Unreleased]now says values are trimmed.Was AI used in this pull request?