Repository navigation
Conversation
regexpInitialize set the new options and timeout before it checked whether the Regexp was frozen or already initialized. Re-initializing an initialized Regexp raised TypeError, but the Regexp kept the new options, so `r.send(:initialize, "b", Regexp::IGNORECASE)` turned /a/ into /a/i. CRuby runs rb_reg_initialize_check first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
Review and merge order for the Regexp freeze work (Feature #8948):
|
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.
Regexp#initializechanged the options and timeout of an already initialized Regexp before raisingTypeError, so a failed re-initialize still modified the Regexp:r = Class.new(Regexp).new("a")r.send(:initialize, "b", Regexp::IGNORECASE) rescue nilr/a//a/i/a/r.timeoutaftertimeout: 3nil3.0nilChanges
RubyRegexp#regexpInitialize(rb_reg_initialize) now runs the frozen and already-initialized checks before it setsoptionsandtimeout, as CRuby does inrb_reg_initialize_check.This matters more in Ruby 4.1, where every Regexp is frozen (Feature #8948): without the fix, re-initializing a frozen Regexp would change it before
FrozenErroris raised. Theruby-4.1freeze PR carries the same commit.Specs
Added to
core/regexp/initialize_spec.rb: re-initializing a Regexp subclass instance raisesTypeErrorand leaves its options and timeout unchanged. No version guard; it passes on CRuby 3.3, 4.0 and 4.1.Testing
core/regexp/initialize_spec.rb: passes on JRuby (interpreter and forced JIT), CRuby 3.3.12 and 4.0.7. On CRuby 4.1.0-dev the new example passes; the existing "raises a TypeError on an initialized non-literal Regexp" example fails there because 4.1 freezesRegexp.new(it is version-guarded onruby-4.1).mspec ci spec/ruby/core/regexp: 0 failures.test/mri/ruby/test_regexp.rb: 0 failures.🤖 Generated with Claude Code