@@ -1100,7 +1100,7 @@ def visit_integer_node(node)
11001100 def visit_interpolated_regular_expression_node ( node )
11011101 builder . regexp_compose (
11021102 token ( node . opening_loc ) ,
1103- visit_all ( node . parts ) ,
1103+ string_nodes_from_interpolation ( node , node . opening ) ,
11041104 [ node . closing [ 0 ] , srange_offsets ( node . closing_loc . start_offset , node . closing_loc . start_offset + 1 ) ] ,
11051105 builder . regexp_options ( [ node . closing [ 1 ..] , srange_offsets ( node . closing_loc . start_offset + 1 , node . closing_loc . end_offset ) ] )
11061106 )
@@ -2119,6 +2119,7 @@ def string_nodes_from_line_continuations(unescaped, escaped, start_offset, openi
21192119 unescaped = unescaped . lines
21202120 escaped = escaped . lines
21212121 percent_array = opening &.start_with? ( "%w" , "%W" , "%i" , "%I" )
2122+ regex = opening == "/" || opening &.start_with? ( "%r" )
21222123
21232124 # Non-interpolating strings
21242125 if opening &.end_with? ( "'" ) || opening &.start_with? ( "%q" , "%s" , "%w" , "%i" )
@@ -2153,11 +2154,18 @@ def string_nodes_from_line_continuations(unescaped, escaped, start_offset, openi
21532154 . chunk_while { |before , after | before [ /(\\ *)\r ?\n $/ , 1 ] &.length &.odd? || false }
21542155 . each do |lines |
21552156 escaped_lengths << lines . sum ( &:bytesize )
2156- unescaped_lines_count = lines . sum do |line |
2157- count = line . scan ( /(\\ *)n/ ) . count { |( backslashes ) | backslashes &.length &.odd? }
2158- count -= 1 if !line . end_with? ( "\n " ) && count > 0
2159- count
2160- end
2157+
2158+ unescaped_lines_count =
2159+ if regex
2160+ 0 # Will always be preserved as is
2161+ else
2162+ lines . sum do |line |
2163+ count = line . scan ( /(\\ *)n/ ) . count { |( backslashes ) | backslashes &.length &.odd? }
2164+ count -= 1 if !line . end_with? ( "\n " ) && count > 0
2165+ count
2166+ end
2167+ end
2168+
21612169 extra = 1
21622170 extra = lines . count if percent_array # Account for line continuations in percent arrays
21632171
0 commit comments