Skip to content

Commit 0776212

Browse files
committed
Remove excess whitespace before validation.
1 parent ec01acd commit 0776212

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

Diff for: app/models/gitolite_public_key.rb

+5-4
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,12 @@ def self.user_to_user_token(user)
9898

9999
# Strip leading and trailing whitespace
100100
def strip_whitespace
101-
# Don't mess with existing keys (since cannot change key text anyway)
102-
return if !new_record?
103-
104101
self.title = title.strip
105-
self.key = key.strip
102+
103+
# Don't mess with existing keys (since cannot change key text anyway)
104+
if new_record?
105+
self.key = key.strip
106+
end
106107
end
107108

108109
# Remove control characters from key

Diff for: app/models/repository_mirror.rb

+8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class RepositoryMirror < ActiveRecord::Base
1616

1717
validate :check_refspec
1818

19+
before_validation :strip_whitespace
20+
1921
named_scope :active, {:conditions => {:active => RepositoryMirror::STATUS_ACTIVE}}
2022
named_scope :inactive, {:conditions => {:active => RepositoryMirror::STATUS_INACTIVE}}
2123

@@ -77,6 +79,12 @@ def to_s
7779

7880
protected
7981

82+
# Strip leading and trailing whitespace
83+
def strip_whitespace
84+
self.url = url.strip
85+
self.explicit_refspec = explicit_refspec.strip
86+
end
87+
8088
# Put backquote in front of crucial characters
8189
def dequote(in_string)
8290
in_string.gsub(/[$,"\\\n]/) {|x| "\\"+x}

Diff for: app/models/repository_post_receive_url.rb

+10-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ class RepositoryPostReceiveUrl < ActiveRecord::Base
77
attr_accessible :url, :mode, :active
88

99
validates_uniqueness_of :url, :scope => [:project_id]
10-
validates_presence_of :project_id, :url
10+
validates_presence_of :project_id
1111
validates_format_of :url, :with => URI::regexp(%w(http https))
1212
validates_associated :project
1313

14+
before_validation :strip_whitespace
15+
1416
named_scope :active, {:conditions => {:active => RepositoryPostReceiveUrl::STATUS_ACTIVE}}
1517
named_scope :inactive, {:conditions => {:active => RepositoryPostReceiveUrl::STATUS_INACTIVE}}
1618

@@ -25,4 +27,11 @@ def mode= (value)
2527
def to_s
2628
return File.join("#{project.identifier}-#{url}")
2729
end
30+
31+
protected
32+
33+
# Strip leading and trailing whitespace
34+
def strip_whitespace
35+
self.url = url.strip
36+
end
2837
end

0 commit comments

Comments
 (0)