From 65cf350231e94f42fa9709e1a81d6adb69e32f39 Mon Sep 17 00:00:00 2001 From: Prommah Date: Thu, 24 Sep 2015 07:23:05 +0100 Subject: [PATCH] Improve & clean SteamID validation --- app/models/user.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) mode change 100644 => 100755 app/models/user.rb diff --git a/app/models/user.rb b/app/models/user.rb old mode 100644 new mode 100755 index 04465fd..4d50141 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -243,13 +243,14 @@ class User < ActiveRecord::Base end def validate_steamid - if !(self.steamid.nil? || (m = self.steamid.match(/\A([01]):([01]):(\d{1,10})\Z/) and accid = (m[3].to_i<<1)+m[2].to_i and accid > 0 and accid <= 4294967295)) - errors.add :steamid - end + errors.add :steamid unless self.steamid.nil? || + (m = self.steamid.match(/\A([01]):([01]):(\d{1,10})\Z/)) && + (id = m[3].to_i) && + id >= 1 && id <= 2147483647 end def correct_steamid_universe - if self.steamid + if self.steamid.present? self.steamid[0] = "0" end end