Skip to content

Commit b201474

Browse files
committed
Should escape meta characters in regexp
1 parent af58740 commit b201474

30 files changed

+118
-118
lines changed

actionmailer/test/log_subscriber_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_deliver_is_notified
2626
wait
2727

2828
assert_equal(1, @logger.logged(:info).size)
29-
assert_match(/Sent mail to [email protected]/, @logger.logged(:info).first)
29+
assert_match(/Sent mail to system@test\.lindsaar\.net/, @logger.logged(:info).first)
3030

3131
assert_equal(2, @logger.logged(:debug).size)
3232
assert_match(/BaseMailer#welcome: processed outbound mail in [\d.]+ms/, @logger.logged(:debug).first)

actionpack/test/dispatch/request_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ class RequestIP < BaseRequestTest
110110
request.remote_ip
111111
}
112112
assert_match(/IP spoofing attack/, e.message)
113-
assert_match(/HTTP_X_FORWARDED_FOR="1.1.1.1"/, e.message)
114-
assert_match(/HTTP_CLIENT_IP="2.2.2.2"/, e.message)
113+
assert_match(/HTTP_X_FORWARDED_FOR="1\.1\.1\.1"/, e.message)
114+
assert_match(/HTTP_CLIENT_IP="2\.2\.2\.2"/, e.message)
115115
end
116116

117117
test "remote ip with spoof detection disabled" do

actionview/test/activerecord/controller_runtime_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def test_runtime_reset_before_requests
6767
wait
6868

6969
assert_equal 2, @logger.logged(:info).size
70-
assert_match(/\(Views: [\d.]+ms \| ActiveRecord: 0.0ms\)/, @logger.logged(:info)[1])
70+
assert_match(/\(Views: [\d.]+ms \| ActiveRecord: 0\.0ms\)/, @logger.logged(:info)[1])
7171
end
7272

7373
def test_log_with_active_record_when_post

actionview/test/template/asset_tag_helper_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -709,13 +709,13 @@ def test_should_ignore_asset_host_on_scheme_relative_url
709709

710710
def test_should_wildcard_asset_host
711711
@controller.config.asset_host = "http://a%d.example.com"
712-
assert_match(%r(http://a[0123].example.com), compute_asset_host("foo"))
712+
assert_match(%r(http://a[0123]\.example\.com), compute_asset_host("foo"))
713713
end
714714

715715
def test_should_wildcard_asset_host_between_zero_and_four
716716
@controller.config.asset_host = "http://a%d.example.com"
717-
assert_match(%r(http://a[0123].example.com/collaboration/hieraki/images/xml.png), image_path("xml.png"))
718-
assert_match(%r(http://a[0123].example.com/collaboration/hieraki/images/xml.png), image_url("xml.png"))
717+
assert_match(%r(http://a[0123]\.example\.com/collaboration/hieraki/images/xml\.png), image_path("xml.png"))
718+
assert_match(%r(http://a[0123]\.example\.com/collaboration/hieraki/images/xml\.png), image_url("xml.png"))
719719
end
720720

721721
def test_asset_host_without_protocol_should_be_protocol_relative

actionview/test/template/atom_feed_helper_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ def test_feed_should_include_atomPub_namespace
301301
with_restful_routing(:scrolls) do
302302
get :index, params: { id: "feed_with_atomPub_namespace" }
303303
assert_match %r{xml:lang="en-US"}, @response.body
304-
assert_match %r{xmlns="http://www.w3.org/2005/Atom"}, @response.body
305-
assert_match %r{xmlns:app="http://www.w3.org/2007/app"}, @response.body
304+
assert_match %r{xmlns="http://www\.w3\.org/2005/Atom"}, @response.body
305+
assert_match %r{xmlns:app="http://www\.w3\.org/2007/app"}, @response.body
306306
end
307307
end
308308

@@ -319,7 +319,7 @@ def test_feed_xml_processing_instructions
319319
with_restful_routing(:scrolls) do
320320
get :index, params: { id: "feed_with_xml_processing_instructions" }
321321
assert_match %r{<\?xml-stylesheet [^\?]*type="text/css"}, @response.body
322-
assert_match %r{<\?xml-stylesheet [^\?]*href="t.css"}, @response.body
322+
assert_match %r{<\?xml-stylesheet [^\?]*href="t\.css"}, @response.body
323323
end
324324
end
325325

@@ -334,7 +334,7 @@ def test_feed_xml_processing_instructions_duplicate_targets
334334
def test_feed_xhtml
335335
with_restful_routing(:scrolls) do
336336
get :index, params: { id: "feed_with_xhtml_content" }
337-
assert_match %r{xmlns="http://www.w3.org/1999/xhtml"}, @response.body
337+
assert_match %r{xmlns="http://www\.w3\.org/1999/xhtml"}, @response.body
338338
assert_select "summary", text: /Something Boring/
339339
assert_select "summary", text: /after 2/
340340
end

actionview/test/template/render_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def fragment_cache_key(key)
2727

2828
def test_render_without_options
2929
e = assert_raises(ArgumentError) { @view.render() }
30-
assert_match(/You invoked render but did not give any of (.+) option./, e.message)
30+
assert_match(/You invoked render but did not give any of (.+) option\./, e.message)
3131
end
3232

3333
def test_render_file
@@ -261,7 +261,7 @@ def test_render_error_indentation
261261
def test_render_sub_template_with_errors
262262
e = assert_raises(ActionView::Template::Error) { @view.render(template: "test/sub_template_raise") }
263263
assert_match %r!method.*doesnt_exist!, e.message
264-
assert_match %r{Trace of template inclusion: .*test/sub_template_raise.html.erb}, e.sub_template_message
264+
assert_match %r{Trace of template inclusion: .*test/sub_template_raise\.html\.erb}, e.sub_template_message
265265
assert_equal "1", e.line_number
266266
assert_equal File.expand_path("#{FIXTURE_LOAD_PATH}/test/_raise.html.erb"), e.file_name
267267
end

activerecord/test/cases/adapters/mysql2/charset_collation_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Mysql2CharsetCollationTest < ActiveRecord::Mysql2TestCase
4848

4949
test "schema dump includes collation" do
5050
output = dump_table_schema("charset_collations")
51-
assert_match %r{t.string\s+"string_ascii_bin",\s+collation: "ascii_bin"$}, output
52-
assert_match %r{t.text\s+"text_ucs2_unicode_ci",\s+collation: "ucs2_unicode_ci"$}, output
51+
assert_match %r{t\.string\s+"string_ascii_bin",\s+collation: "ascii_bin"$}, output
52+
assert_match %r{t\.text\s+"text_ucs2_unicode_ci",\s+collation: "ucs2_unicode_ci"$}, output
5353
end
5454
end

activerecord/test/cases/adapters/mysql2/unsigned_type_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ class UnsignedType < ActiveRecord::Base
5858

5959
test "schema dump includes unsigned option" do
6060
schema = dump_table_schema "unsigned_types"
61-
assert_match %r{t.integer\s+"unsigned_integer",\s+unsigned: true$}, schema
62-
assert_match %r{t.bigint\s+"unsigned_bigint",\s+unsigned: true$}, schema
63-
assert_match %r{t.float\s+"unsigned_float",\s+limit: 24,\s+unsigned: true$}, schema
64-
assert_match %r{t.decimal\s+"unsigned_decimal",\s+precision: 10,\s+scale: 2,\s+unsigned: true$}, schema
61+
assert_match %r{t\.integer\s+"unsigned_integer",\s+unsigned: true$}, schema
62+
assert_match %r{t\.bigint\s+"unsigned_bigint",\s+unsigned: true$}, schema
63+
assert_match %r{t\.float\s+"unsigned_float",\s+limit: 24,\s+unsigned: true$}, schema
64+
assert_match %r{t\.decimal\s+"unsigned_decimal",\s+precision: 10,\s+scale: 2,\s+unsigned: true$}, schema
6565
end
6666
end

activerecord/test/cases/adapters/postgresql/collation_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def teardown
4747

4848
test "schema dump includes collation" do
4949
output = dump_table_schema("postgresql_collations")
50-
assert_match %r{t.string\s+"string_c",\s+collation: "C"$}, output
51-
assert_match %r{t.text\s+"text_posix",\s+collation: "POSIX"$}, output
50+
assert_match %r{t\.string\s+"string_c",\s+collation: "C"$}, output
51+
assert_match %r{t\.text\s+"text_posix",\s+collation: "POSIX"$}, output
5252
end
5353
end

activerecord/test/cases/adapters/postgresql/explain_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ class PostgreSQLExplainTest < ActiveRecord::PostgreSQLTestCase
77

88
def test_explain_for_one_query
99
explain = Developer.where(id: 1).explain
10-
assert_match %r(EXPLAIN for: SELECT "developers".* FROM "developers" WHERE "developers"."id" = (?:\$1 \[\["id", 1\]\]|1)), explain
10+
assert_match %r(EXPLAIN for: SELECT "developers"\.\* FROM "developers" WHERE "developers"\."id" = (?:\$1 \[\["id", 1\]\]|1)), explain
1111
assert_match %(QUERY PLAN), explain
1212
end
1313

1414
def test_explain_with_eager_loading
1515
explain = Developer.where(id: 1).includes(:audit_logs).explain
1616
assert_match %(QUERY PLAN), explain
17-
assert_match %r(EXPLAIN for: SELECT "developers".* FROM "developers" WHERE "developers"."id" = (?:\$1 \[\["id", 1\]\]|1)), explain
17+
assert_match %r(EXPLAIN for: SELECT "developers"\.\* FROM "developers" WHERE "developers"\."id" = (?:\$1 \[\["id", 1\]\]|1)), explain
1818
assert_match %(EXPLAIN for: SELECT "audit_logs".* FROM "audit_logs" WHERE "audit_logs"."developer_id" = 1), explain
1919
end
2020
end

0 commit comments

Comments
 (0)