public
Fork of rails/rails
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/JackDanger/rails.git
Fixed that when using validation macros with a custom message, if you 
happened to use single quotes in the message string you would get a 
parsing error #657 [tonka]


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@740 
5ecf4fe2-1ee6-0310-87b1-e25e094e27de
dhh (author)
Tue Feb 22 05:54:26 -0800 2005
commit  dfd43d577eaaf4b9c157f6379045d1e2fb68d1ee
tree    76078e64131c52bb7b87975da973f689daa8b06b
parent  148f6d8fb6ea028b2738a0553f058e903268a0b8
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *SVN*
0
 
0
+* Fixed that when using validation macros with a custom message, if you happened to use single quotes in the message string you would get a parsing error #657 [tonka]
0
+
0
 * Fixed that Active Record would throw Broken Pipe errors with FCGI when the MySQL connection timed out instead of reconnecting #428 [Nicholas Seckar]
0
 
0
 * Added options to specify an SSL connection for MySQL. Define the following attributes in the connection config (config/database.yml in Rails) to use it: sslkey, sslcert, sslca, sslcapath, sslcipher. To use SSL with no client certs, just set :sslca = '/dev/null'. http://dev.mysql.com/doc/mysql/en/secure-connections.html #604 [daniel@nightrunner.com]
...
228
229
230
 
231
232
233
...
253
254
255
 
256
257
258
259
 
260
261
262
...
268
269
270
 
271
272
273
...
411
412
413
 
414
415
416
417
 
418
419
 
420
421
422
...
437
438
439
 
440
441
442
...
459
460
461
 
 
462
463
464
...
497
498
499
 
500
501
502
...
228
229
230
231
232
233
234
...
254
255
256
257
258
259
260
 
261
262
263
264
...
270
271
272
273
274
275
276
...
414
415
416
417
418
419
420
 
421
422
 
423
424
425
426
...
441
442
443
444
445
446
447
...
464
465
466
467
468
469
470
471
...
504
505
506
507
508
509
510
0
@@ -228,6 +228,7 @@ module ActiveRecord
0
       def validates_confirmation_of(*attr_names)
0
         configuration = { :message => ActiveRecord::Errors.default_error_messages[:confirmation], :on => :save }
0
         configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)
0
+ configuration[:message].gsub!(/\"/, '\\\\\"')
0
 
0
         for attr_name in attr_names
0
           attr_accessor "#{attr_name}_confirmation"
0
@@ -253,10 +254,11 @@ module ActiveRecord
0
       def validates_acceptance_of(*attr_names)
0
         configuration = { :message => ActiveRecord::Errors.default_error_messages[:accepted], :on => :save }
0
         configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)
0
+ configuration[:message].gsub!(/\"/, '\\\\\"')
0
 
0
         for attr_name in attr_names
0
           attr_accessor(attr_name)
0
- class_eval(%(#{validation_method(configuration[:on])} %{errors.add('#{attr_name}', '#{configuration[:message]}') unless #{attr_name}.nil? or #{attr_name} == "1"}))
0
+ class_eval(%(#{validation_method(configuration[:on])} %{errors.add('#{attr_name}', "#{configuration[:message]}") unless #{attr_name}.nil? or #{attr_name} == "1"}))
0
         end
0
       end
0
 
0
@@ -268,6 +270,7 @@ module ActiveRecord
0
       def validates_presence_of(*attr_names)
0
         configuration = { :message => ActiveRecord::Errors.default_error_messages[:empty], :on => :save }
0
         configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)
0
+ configuration[:message].gsub!(/\"/, '\\\\\"')
0
 
0
         for attr_name in attr_names
0
           class_eval(%(#{validation_method(configuration[:on])} %{errors.add_on_empty('#{attr_name}', "#{configuration[:message]}")}))
0
@@ -411,12 +414,13 @@ module ActiveRecord
0
       def validates_uniqueness_of(*attr_names)
0
         configuration = { :message => ActiveRecord::Errors.default_error_messages[:taken] }
0
         configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)
0
+ configuration[:message].gsub!(/\"/, '\\\\\"')
0
 
0
         for attr_name in attr_names
0
           if scope = configuration[:scope]
0
- class_eval(%(validate %{errors.add('#{attr_name}', '#{configuration[:message]}') if self.class.find_first(new_record? ? ['#{attr_name} = ? AND #{scope} = ?', #{attr_name}, #{scope}] : ["#{attr_name} = ? AND \\\#{self.class.primary_key} <> ? AND #{scope} = ?", #{attr_name}, id, #{scope}])}))
0
+ class_eval(%(validate %{errors.add('#{attr_name}', "#{configuration[:message]}") if self.class.find_first(new_record? ? ['#{attr_name} = ? AND #{scope} = ?', #{attr_name}, #{scope}] : ["#{attr_name} = ? AND \\\#{self.class.primary_key} <> ? AND #{scope} = ?", #{attr_name}, id, #{scope}])}))
0
           else
0
- class_eval(%(validate %{errors.add('#{attr_name}', '#{configuration[:message]}') if self.class.find_first(new_record? ? ['#{attr_name} = ?', #{attr_name}] : ["#{attr_name} = ? AND \\\#{self.class.primary_key} <> ?", #{attr_name}, id])}))
0
+ class_eval(%(validate %{errors.add('#{attr_name}', "#{configuration[:message]}") if self.class.find_first(new_record? ? ['#{attr_name} = ?', #{attr_name}] : ["#{attr_name} = ? AND \\\#{self.class.primary_key} <> ?", #{attr_name}, id])}))
0
           end
0
         end
0
       end
0
@@ -437,6 +441,7 @@ module ActiveRecord
0
       def validates_format_of(*attr_names)
0
         configuration = { :message => ActiveRecord::Errors.default_error_messages[:invalid], :on => :save, :with => nil }
0
         configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)
0
+ configuration[:message].gsub!(/\"/, '\\\\\"')
0
 
0
         raise(ArgumentError, "A regular expression must be supplied as the :with option of the configuration hash") unless configuration[:with].is_a?(Regexp)
0
 
0
@@ -459,6 +464,8 @@ module ActiveRecord
0
       def validates_inclusion_of(*attr_names)
0
         configuration = { :message => ActiveRecord::Errors.default_error_messages[:inclusion], :on => :save }
0
         configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)
0
+ configuration[:message].gsub!(/\"/, '\\\\\"')
0
+
0
         enum = configuration[:in] || configuration[:within]
0
         allow_nil = configuration[:allow_nil]
0
 
0
@@ -497,6 +504,7 @@ module ActiveRecord
0
       def validates_associated(*attr_names)
0
         configuration = { :message => ActiveRecord::Errors.default_error_messages[:invalid], :on => :save }
0
         configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)
0
+ configuration[:message].gsub!(/\"/, '\\\\\"')
0
         
0
         for attr_name in attr_names
0
           class_eval(%(#{validation_method(configuration[:on])} %{
...
522
523
524
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
525
...
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
0
@@ -522,4 +522,86 @@ class ValidationsTest < Test::Unit::TestCase
0
     assert_equal 100, d.salary
0
     assert_equal "100,000", d.salary_before_type_cast
0
   end
0
+
0
+ def test_validates_acceptance_of_with_custom_error_using_quotes
0
+ Developer.validates_acceptance_of :salary, :message=> "This string contains 'single' and \"double\" quotes"
0
+ d = Developer.new
0
+ d.salary = "0"
0
+ assert !d.valid?
0
+ assert_equal d.errors.on(:salary).first, "This string contains 'single' and \"double\" quotes"
0
+ end
0
+
0
+ def test_validates_confirmation_of_with_custom_error_using_quotes
0
+ Developer.validates_confirmation_of :name, :message=> "This string contains 'single' and \"double\" quotes"
0
+ d = Developer.new
0
+ d.name = "John"
0
+ d.name_confirmation = "Johnny"
0
+ assert !d.valid?
0
+ assert_equal d.errors.on(:name), "This string contains 'single' and \"double\" quotes"
0
+ end
0
+
0
+ def test_validates_format_of_with_custom_error_using_quotes
0
+ Developer.validates_format_of :name, :with => /^(A-Z*)$/, :message=> "This string contains 'single' and \"double\" quotes"
0
+ d = Developer.new
0
+ d.name = "John 32"
0
+ assert !d.valid?
0
+ assert_equal d.errors.on(:name), "This string contains 'single' and \"double\" quotes"
0
+ end
0
+
0
+ def test_validates_inclusion_of_with_custom_error_using_quotes
0
+ Developer.validates_inclusion_of :salary, :in => 1000..80000, :message=> "This string contains 'single' and \"double\" quotes"
0
+ d = Developer.new
0
+ d.salary = "90,000"
0
+ assert !d.valid?
0
+ assert_equal d.errors.on(:salary).first, "This string contains 'single' and \"double\" quotes"
0
+ end
0
+
0
+ def test_validates_length_of_with_custom_too_long_using_quotes
0
+ Developer.validates_length_of :name, :maximum => 4, :too_long=> "This string contains 'single' and \"double\" quotes"
0
+ d = Developer.new
0
+ d.name = "Jeffrey"
0
+ assert !d.valid?
0
+ assert_equal d.errors.on(:name).first, "This string contains 'single' and \"double\" quotes"
0
+ end
0
+
0
+ def test_validates_length_of_with_custom_too_short_using_quotes
0
+ Developer.validates_length_of :name, :minimum => 4, :too_short=> "This string contains 'single' and \"double\" quotes"
0
+ d = Developer.new
0
+ d.name = "Joe"
0
+ assert !d.valid?
0
+ assert_equal d.errors.on(:name).first, "This string contains 'single' and \"double\" quotes"
0
+ end
0
+
0
+ def test_validates_length_of_with_custom_message_using_quotes
0
+ Developer.validates_length_of :name, :minimum => 4, :message=> "This string contains 'single' and \"double\" quotes"
0
+ d = Developer.new
0
+ d.name = "Joe"
0
+ assert !d.valid?
0
+ assert_equal d.errors.on(:name).first, "This string contains 'single' and \"double\" quotes"
0
+ end
0
+
0
+ def test_validates_presence_of_with_custom_message_using_quotes
0
+ Developer.validates_presence_of :non_existent, :message=> "This string contains 'single' and \"double\" quotes"
0
+ d = Developer.new
0
+ d.name = "Joe"
0
+ assert !d.valid?
0
+ assert_equal d.errors.on(:non_existent), "This string contains 'single' and \"double\" quotes"
0
+ end
0
+
0
+ def test_validates_uniqueness_of_with_custom_message_using_quotes
0
+ Developer.validates_uniqueness_of :name, :message=> "This string contains 'single' and \"double\" quotes"
0
+ d = Developer.new
0
+ d.name = "David"
0
+ assert !d.valid?
0
+ assert_equal d.errors.on(:name).first, "This string contains 'single' and \"double\" quotes"
0
+ end
0
+
0
+ def test_validates_associated_with_custom_message_using_quotes
0
+ Reply.validates_associated :topic, :message=> "This string contains 'single' and \"double\" quotes"
0
+ Topic.validates_presence_of :content
0
+ r = Reply.create("title" => "A reply", "content" => "with content!")
0
+ r.topic = Topic.create("title" => "uhohuhoh")
0
+ assert !r.valid?
0
+ assert_equal r.errors.on(:topic).first, "This string contains 'single' and \"double\" quotes"
0
+ end
0
 end

Comments

    No one has commented yet.