Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: edge case on context value where trim is not a function #648

Merged
merged 1 commit into from
Jul 23, 2024

Conversation

nunogois
Copy link
Member

@nunogois nunogois commented Jul 23, 2024

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:

image

Lastly, we noticed the test files strategy-test.ts and flexible-rollout-test.ts were being ignored in test runs due to their filename format. Renaming them to strategy.test.ts and flexible-rollout.test.ts ensures they are included in the tests as intended.

@coveralls
Copy link

Coverage Status

coverage: 90.635% (+0.2%) from 90.456%
when pulling 28a584a on fix-context-edge-case-trim-not-a-function
into e61e55a on main.

Copy link
Member

@chriswk chriswk left a comment

Choose a reason for hiding this comment

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

Nice. Strange corner case.

@nunogois nunogois merged commit 2ccb88a into main Jul 23, 2024
5 checks passed
@nunogois nunogois deleted the fix-context-edge-case-trim-not-a-function branch July 23, 2024 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

unleash-proxy crashes with 'version.trim is not a function'
3 participants