summaryrefslogtreecommitdiff
path: root/app/models/key.rb
diff options
context:
space:
mode:
authorRubén Dávila <ruben@gitlab.com>2018-02-01 17:00:16 -0500
committerRubén Dávila <ruben@gitlab.com>2018-02-01 17:00:16 -0500
commit972f564dcd897ee66799c19f96ed22df588f8a18 (patch)
tree85e88470019c9e9fbce725f81d12dfef03872e66 /app/models/key.rb
parent078dac4268cb5e991cc0012f5ad01ca3cb9a39c8 (diff)
downloadgitlab-ce-972f564dcd897ee66799c19f96ed22df588f8a18.tar.gz
Sanitize extra blank spaces used when uploading a SSH key
Diffstat (limited to 'app/models/key.rb')
-rw-r--r--app/models/key.rb7
1 files changed, 3 insertions, 4 deletions
diff --git a/app/models/key.rb b/app/models/key.rb
index a3f8a5d6dc7..cfa009f212f 100644
--- a/app/models/key.rb
+++ b/app/models/key.rb
@@ -34,9 +34,8 @@ class Key < ActiveRecord::Base
after_destroy :refresh_user_cache
def key=(value)
- value&.delete!("\n\r")
- value.strip! unless value.blank?
- write_attribute(:key, value)
+ write_attribute(:key, value.present? ? Gitlab::SSHPublicKey.sanitize(value) : nil)
+
@public_key = nil
end
@@ -98,7 +97,7 @@ class Key < ActiveRecord::Base
def generate_fingerprint
self.fingerprint = nil
- return unless self.key.present?
+ return unless public_key.valid?
self.fingerprint = public_key.fingerprint
end