Bug #770

assert_match should escape string argument

Added by bitsweat (Jeremy Kemper) over 3 years ago. Updated about 1 year ago.

[ruby-core:20013]
Status:Closed Start date:11/21/2008
Priority:High Due date:
Assignee:zenspider (Ryan Davis) % Done:

0%

Category:-
Target version:1.9.1 Release Candidate
ruby -v:

Description

String expectation for assert_match should be matched literally, not as a regexp.

test/unit: assert_match '.', 'a'  #=> fails
minitest: assert_match '.', 'a' #=> passes

Index: lib/minitest/unit.rb
===================================================================
--- lib/minitest/unit.rb	(revision 20290)
+++ lib/minitest/unit.rb	(working copy)
@@ -118,7 +118,7 @@
     def assert_match exp, act, msg = nil
       msg = message(msg) { "Expected #{mu_pp(act)} to match #{mu_pp(exp)}" }
       assert_respond_to act, :"=~"
-      (exp = /#{exp}/) if String === exp && String === act
+      (exp = /#{Regexp.escape(exp)}/) if String === exp && String === act
       assert act =~ exp, msg
     end

History

Updated by yugui (Yuki Sonoda) over 3 years ago

  • Status changed from Open to Assigned
  • Priority changed from Normal to High
  • Target version set to 1.9.1 Release Candidate
Right.

Matz, ko1, nakada, akr and yugui thought this patch should be merged.

Updated by zenspider (Ryan Davis) over 3 years ago

  • Status changed from Assigned to Closed
fixed. thanks.

Also available in: Atom PDF