fix(flags): reject leading-zero semver values in local evaluation#150
Open
dmarticus wants to merge 1 commit into
Open
fix(flags): reject leading-zero semver values in local evaluation#150dmarticus 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 raise InconclusiveMatchError so the condition does not match.
marandaneto
approved these changes
May 21, 2026
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.
💡 Motivation and Context
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 (via the/^\d+$/regex +to_i, so"07".to_i → 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 raise
InconclusiveMatchErrorso the condition simply does not match.This mirrors the same fix already shipped in posthog-python (#601), posthog-go (#200), posthog-rs (#112), posthog-js/node (#3643), posthog-php (#147), posthog-dotnet (#206), and posthog-android/posthog-server (#521).
Changes
parse_semvernow uses a newparse_semver_numerichelper that rejects empty, non-digit, and leading-zero strings (except literal"0").semver_wildcard_boundsuses the same helper, so01.*and1.07.*are rejected.01.02.03matched1.2.3— it now correctly rejects.01.2.3,1.02.3,1.2.03,1.07.3,001.2.3), flag values acrosssemver_gt/semver_caret/semver_tilde/semver_wildcard, and that literal0components (0.1.0,1.0.0,0.0.0) still match.💚 How did you test it?
bundle exec rspec spec/posthog/feature_flag_spec.rb -e "semver"— 21 examples, 0 failuresbundle exec rspec— full suite passes (one pre-existing timing-flaky test insend_worker_spec, passes in isolation, unrelated to this change)bundle exec rubocop lib/posthog/feature_flags.rb spec/posthog/feature_flag_spec.rb— clean📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset filereleaselabel to the PR