Skip to content

🐛 Fixes [Bug #20039](https://bugs.ruby-lang.org/issues/20039) #9120

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

Conversation

dustinbrownman
Copy link
Contributor

When a Regexp is initialized with another Regexp, we simply copy the properties from the original. However, the flags on the original were not being copied correctly. This caused an issue when the original had multibyte characters and was being compared with an ASCII string. Without the forced encoding flag (KCODE_FIXED) transferred on to the new Regexp, the comparison would fail. See the included test for an example.

Comment on lines 1943 to 1944
str.match?(re)
str.match?(Regexp.new(re))
Copy link
Member

Choose a reason for hiding this comment

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

Needs assertions, or should comment that we expect no exception here, at least.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the feedback. I changed this to use assert_nothing_raised.

@dustinbrownman dustinbrownman force-pushed the dustinbrownman/fix-regexp-copying-encoding-error branch from 27d1d18 to f0dc0eb Compare December 5, 2023 18:25
When a Regexp is initialized with another Regexp, we simply copy the
properties from the original. However, the flags on the original were
not being copied correctly. This caused an issue when the original had
multibyte characters and was being compared with an ASCII string.
Without the forced encoding flag (`KCODE_FIXED`) transferred on to the
new Regexp, the comparison would fail. See the included test for an
example.
@dustinbrownman dustinbrownman force-pushed the dustinbrownman/fix-regexp-copying-encoding-error branch from f0dc0eb to 7b917dc Compare December 5, 2023 18:41
Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
@jhawthorn jhawthorn merged commit d89280e into ruby:master Dec 7, 2023
@dustinbrownman dustinbrownman deleted the dustinbrownman/fix-regexp-copying-encoding-error branch December 7, 2023 16:21
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.

3 participants