File tree Expand file tree Collapse file tree 5 files changed +26
-15
lines changed
java/org/truffleruby/core/regexp Expand file tree Collapse file tree 5 files changed +26
-15
lines changed Original file line number Diff line number Diff line change 776
776
[ Meths , MethsMore , Regexp ]
777
777
end
778
778
779
- it "loads a extended_user_regexp having ivar " do
779
+ it "loads a Regexp subclass instance variables when it is extended with a module " do
780
780
obj = UserRegexp . new ( '' ) . extend ( Meths )
781
781
obj . instance_variable_set ( :@noise , 'much' )
782
782
799
799
new_obj . instance_variable_get ( :@regexp_ivar ) . should == [ 42 ]
800
800
end
801
801
end
802
+
803
+ it "preserves Regexp encoding" do
804
+ source_object = Regexp . new ( "a" . encode ( "utf-32le" ) )
805
+ regexp = Marshal . send ( @method , Marshal . dump ( source_object ) )
806
+
807
+ regexp . encoding . should == Encoding ::UTF_32LE
808
+ regexp . source . should == "a" . encode ( "utf-32le" )
809
+ end
802
810
end
803
811
804
812
describe "for a Float" do
Original file line number Diff line number Diff line change 1
- fails:Marshal.load loads an array containing objects having _dump method, and with proc
2
- fails:Marshal.load loads an array containing objects having marshal_dump method, and with proc
3
1
fails:Marshal.load loads a Random
4
2
fails:Marshal.load when called with a proc returns the value of the proc
5
- fails:Marshal.load when called with a proc calls the proc for recursively visited data
6
3
fails:Marshal.load when called with a proc loads an Array with proc
7
4
fails:Marshal.load for an Array loads an array containing the same objects
8
5
fails:Marshal.load for an Object raises ArgumentError if the object from an 'o' stream is not dumpable as 'o' type user class
@@ -23,3 +20,4 @@ fails:Marshal.load when called with freeze: true when called with a proc does no
23
20
fails:Marshal.load when called with freeze: true does freeze extended objects
24
21
fails:Marshal.load when called with freeze: true does freeze extended objects with instance variables
25
22
fails:Marshal.load for a Regexp restore the regexp instance variables
23
+ fails:Marshal.load for a Regexp loads a Regexp subclass instance variables when it is extended with a module
Original file line number Diff line number Diff line change 1
- fails:Marshal.restore loads an array containing objects having _dump method, and with proc
2
- fails:Marshal.restore loads an array containing objects having marshal_dump method, and with proc
3
1
fails:Marshal.restore loads a Random
4
2
fails:Marshal.restore when called with a proc returns the value of the proc
5
- fails:Marshal.restore when called with a proc calls the proc for recursively visited data
6
3
fails:Marshal.restore when called with a proc loads an Array with proc
7
4
fails:Marshal.restore for an Array loads an array containing the same objects
8
5
fails:Marshal.restore for an Object raises ArgumentError if the object from an 'o' stream is not dumpable as 'o' type user class
@@ -23,3 +20,4 @@ fails:Marshal.restore when called with freeze: true when called with a proc does
23
20
fails:Marshal.restore when called with freeze: true does freeze extended objects
24
21
fails:Marshal.restore when called with freeze: true does freeze extended objects with instance variables
25
22
fails:Marshal.restore for a Regexp restore the regexp instance variables
23
+ fails:Marshal.restore for a Regexp loads a Regexp subclass instance variables when it is extended with a module
Original file line number Diff line number Diff line change @@ -75,9 +75,6 @@ public static RubyRegexp create(RubyLanguage language,
75
75
public final TRegexCache tregexCache ;
76
76
77
77
private RubyRegexp (Regex regex , RegexpOptions options ) {
78
- // The RegexpNodes.compile operation may modify the encoding of the source rope. This modified copy is stored
79
- // in the Regex object as the "user object". Since ropes are immutable, we need to take this updated copy when
80
- // constructing the final regexp.
81
78
this .regex = regex ;
82
79
final TStringWithEncoding tstringWithEncoding = (TStringWithEncoding ) regex .getUserObject ();
83
80
this .source = tstringWithEncoding .tstring ;
Original file line number Diff line number Diff line change @@ -641,7 +641,7 @@ def construct(ivar_index = nil, call_proc = true)
641
641
when 34 # ?"
642
642
construct_string
643
643
when 47 # ?/
644
- construct_regexp
644
+ construct_regexp ( ivar_index )
645
645
when 91 # ?[
646
646
construct_array
647
647
when 123 # ?{
@@ -903,13 +903,23 @@ def construct_integer
903
903
end
904
904
end
905
905
906
- def construct_regexp
907
- s = get_byte_sequence
906
+ def construct_regexp ( ivar_index )
907
+ source = get_byte_sequence
908
+ options = consume_byte
909
+
910
+ # A Regexp instance variables are ignored by CRuby,
911
+ # but we need to know the encoding before building the Regexp
912
+ if ivar_index and @has_ivar [ ivar_index ]
913
+ # This sets the encoding of the String
914
+ set_instance_variables source
915
+ @has_ivar [ ivar_index ] = false
916
+ end
917
+
908
918
if user_class?
909
- obj = user_class . new s , consume_byte
919
+ obj = user_class . new source , options
910
920
clear_user_class
911
921
else
912
- obj = Regexp . new s , consume_byte
922
+ obj = Regexp . new source , options
913
923
end
914
924
915
925
store_unique_object obj
You can’t perform that action at this time.
0 commit comments