fix: edge case on context value where trim is not a function #648
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.
https://linear.app/unleash/issue/2-2468/fix-trim-is-not-a-function-edge-case-on-context-value
Fixes: Unleash/unleash-proxy#185
This PR addresses the issue reported by @nicks, where a
version.trim is not a function
error is thrown under certain conditions.The error occurs when a context value has a custom
.toString()
method that does not return a string. This was the only scenario in which we could reproduce the issue. A corresponding test has been added to validate this.The solution suggested by @nicks has been implemented. Specifically, the
!isStrictSemver(contextValue)
check has been moved inside the try/catch block. This change ensures that any exceptions thrown by this method will be caught, in which case the function will default to false.A more robust implementation of
resolveContextValue
has been introduced, which would also prevent the issue. See:Lastly, we noticed the test files
strategy-test.ts
andflexible-rollout-test.ts
were being ignored in test runs due to their filename format. Renaming them tostrategy.test.ts
andflexible-rollout.test.ts
ensures they are included in the tests as intended.