fix: reject leading-zero semver values in local evaluation#147
Open
dmarticus wants to merge 1 commit into
Open
fix: reject leading-zero semver values in local evaluation#147dmarticus wants to merge 1 commit into
dmarticus wants to merge 1 commit into
Conversation
Per semver 2.0.0 §2, numeric identifiers must not include leading zeros. Values like "1.07.3" are not valid semver and should not match targeting conditions. Both override values and flag values are validated; invalid inputs surface an InconclusiveMatchError so the condition does not match.
6 tasks
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
Per semver 2.0.0 §2, numeric identifiers MUST NOT include leading zeros. Values like
1.07.3or01.2.3are not valid semver — the local feature flag evaluator currently parses them silently (viaintval("07") → 7), which means a person property of1.07.3would incorrectly match asemver_eqcondition against1.7.3.This PR makes the parser reject leading zeros in numeric identifiers. Both override values and flag values are validated; invalid inputs throw
InconclusiveMatchExceptionso the condition simply does not match.Matches the same fix applied to posthog-python #601 and posthog-go #200.
Changes
parseSemvernow uses aparseSemverNumerichelper that rejects strings with leading zeros (except literal"0").wildcardBoundsuses the same helper, so01.*and1.07.*are rejected.testParseSemverLeadingZeros/testMatchPropertySemverLeadingZeros— they now assert rejection rather than acceptance.semver_gt,semver_caret,semver_tilde,semver_wildcard).Test plan
./vendor/bin/phpunit --filter "Semver|parseSemver" test— 45 passed0components still match (0.1.0,1.0.0,0.0.0)