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: override with fastTest as property on regex object #228

Merged
merged 1 commit into from
Mar 28, 2024

Conversation

legobeat
Copy link
Contributor

The optimized fastTests for common patterns work by overwriting the test property on a RegExp instance. This can cause issues in some locked down runtime environments or trip up static analysis tools.

This uses defineProperty to override the test property on the RegExp instance instead.

resolves issue when running in frozen environments
// Avoids overriding in frozen environments
Reflect.defineProperty(re, 'test', { value: fastTest })
} else {
Object.assign(re, { test: fastTest })
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This preserves existing behavior when re is string while only objects can be handled with defineProperty.

@isaacs isaacs merged commit 87c8677 into isaacs:main Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants