From e1df99fbd9232b4d22de4fa9a55ae7b7269fd176 Mon Sep 17 00:00:00 2001 From: Fabio Teixeira Date: Wed, 1 Oct 2014 17:34:42 -0300 Subject: [PATCH] correcoes_aderencia: Fix full name regex bug --- lib/ext/person.rb | 11 ++++++++++- public/mpog-user-validations.js | 12 +++++++++++- test/unit/mpog_person_test.rb | 2 +- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/ext/person.rb b/lib/ext/person.rb index d23bcd4..baef80b 100644 --- a/lib/ext/person.rb +++ b/lib/ext/person.rb @@ -60,8 +60,17 @@ class Person def validate_full_name reg_firsts_char = /(^|\s)([a-z]|[0-9])/ reg_special_char = /[^\w\*\s]/ + invalid = false - invalid = reg_firsts_char.match(self.name) || reg_special_char.match(self.name) + return false if self.name.blank? + + self.name.split(" ").each do |value| + invalid = if value.length > 3 + reg_firsts_char.match(value) || reg_special_char.match(value) + else + reg_special_char.match(value) + end + end if invalid self.errors.add(:name, _("Should begin with a capital letter and no special characters")) diff --git a/public/mpog-user-validations.js b/public/mpog-user-validations.js index 4265005..197dec1 100644 --- a/public/mpog-user-validations.js +++ b/public/mpog-user-validations.js @@ -92,8 +92,18 @@ function is_invalid_formated(text) { var reg_firsts_char = /(^|\s)([a-z]|[0-9])/g; var reg_special_char = /[^\w\*\s*]/g; + var invalid = false; + var slices = text.split(" "); + + for(var i = 0; i < slices.length; i++) { + if( slices[i].length > 3 ) { + invalid = reg_firsts_char.test(slices[i]) || reg_special_char.test(slices[i]); + } else { + invalid = reg_special_char.test(slices[i]); + } + } - return reg_firsts_char.test(text) || reg_special_char.test(text); + return invalid; } function show_full_name_error_message() { diff --git a/test/unit/mpog_person_test.rb b/test/unit/mpog_person_test.rb index 7179827..04892d1 100644 --- a/test/unit/mpog_person_test.rb +++ b/test/unit/mpog_person_test.rb @@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/../../../../test/test_helper' class MpogSoftwarePluginPersonTest < ActiveSupport::TestCase should 'save person with a valid full name' do - p = Person::new :name=>"S1mpl3 N4m3", :identifier=>"simple-name" + p = Person::new :name=>"S1mpl3 0f N4m3", :identifier=>"simple-name" p.user = fast_create(:user) assert_equal true, p.save -- libgit2 0.21.2