@@ -237,8 +237,27 @@ def test_last_encoding_option_wins
237237 assert_equal Regexp ::NOENCODING , option
238238 end
239239
240+ # A `%r` regexp can use a newline (LF or CRLF) as its delimiter. The closing
241+ # delimiter terminates the regexp and must not be misread as an option -- in
242+ # particular the trailing `\n` of a `\r\n` delimiter.
243+ def test_newline_delimiter
244+ assert_newline_regexp ( "%r\n foo\n " , "foo" , 0 )
245+ assert_newline_regexp ( "%r\r \n foo\r \n " , "foo" , 0 )
246+ assert_newline_regexp ( "%r\r \n foo\r \n i" , "foo" , Regexp ::IGNORECASE )
247+ assert_newline_regexp ( "%r\r \n foo\r \n mix" , "foo" , Regexp ::IGNORECASE | Regexp ::MULTILINE | Regexp ::EXTENDED )
248+ assert_newline_regexp ( "%r\r \n \r \n " , "" , 0 )
249+ end
250+
240251 private
241252
253+ def assert_newline_regexp ( source , content , options )
254+ node = Prism . parse_statement ( source )
255+
256+ assert_kind_of RegularExpressionNode , node
257+ assert_equal content , node . content
258+ assert_equal options , node . options
259+ end
260+
242261 def assert_valid_regexp ( source )
243262 assert Prism . parse_success? ( "/#{ source } / =~ \" \" " )
244263 end
0 commit comments