Skip to content
Snippets Groups Projects
Commit 20ac35e9 authored by Robert Speicher's avatar Robert Speicher
Browse files

Merge branch 'evuez/gitlab-ce-webhook-url-spaces' into 'master'

Strip leading and trailing spaces in URL validator

_Originally opened at !2914 by @evuez._

It makes URLs in webhooks valid even if they contain leading and/or trailing spaces.

Spaces are hard to notice in input fields, this helps users by accepting leading and trailing spaces in webhooks URLs.

Fixes #13652

See merge request !2939
parents 2c6e34bc 4d0e2979
No related branches found
No related tags found
1 merge request!2939Strip leading and trailing spaces in URL validator
Pipeline #
Loading
@@ -3,6 +3,7 @@ Please view this file on the master branch, on stable branches it's out of date.
Loading
@@ -3,6 +3,7 @@ Please view this file on the master branch, on stable branches it's out of date.
v 8.6.0 (unreleased) v 8.6.0 (unreleased)
- Improve the formatting for the user page bio (Connor Shea) - Improve the formatting for the user page bio (Connor Shea)
- Fix avatar stretching by providing a cropping feature (Johann Pardanaud) - Fix avatar stretching by providing a cropping feature (Johann Pardanaud)
- Strip leading and trailing spaces in URL validator (evuez)
   
v 8.5.1 v 8.5.1
- Fix group projects styles - Fix group projects styles
Loading
Loading
Loading
@@ -29,8 +29,11 @@ class UrlValidator < ActiveModel::EachValidator
Loading
@@ -29,8 +29,11 @@ class UrlValidator < ActiveModel::EachValidator
end end
   
def valid_url?(value) def valid_url?(value)
return false if value.nil?
options = default_options.merge(self.options) options = default_options.merge(self.options)
   
value.strip!
value =~ /\A#{URI.regexp(options[:protocols])}\z/ value =~ /\A#{URI.regexp(options[:protocols])}\z/
end end
end end
Loading
@@ -19,6 +19,10 @@
Loading
@@ -19,6 +19,10 @@
require 'spec_helper' require 'spec_helper'
   
describe ProjectHook, models: true do describe ProjectHook, models: true do
describe "Associations" do
it { is_expected.to belong_to :project }
end
describe '.push_hooks' do describe '.push_hooks' do
it 'should return hooks for push events only' do it 'should return hooks for push events only' do
hook = create(:project_hook, push_events: true) hook = create(:project_hook, push_events: true)
Loading
Loading
Loading
@@ -18,20 +18,14 @@
Loading
@@ -18,20 +18,14 @@
   
require 'spec_helper' require 'spec_helper'
   
describe ProjectHook, models: true do describe WebHook, models: true do
describe "Associations" do
it { is_expected.to belong_to :project }
end
describe "Mass assignment" do
end
describe "Validations" do describe "Validations" do
it { is_expected.to validate_presence_of(:url) } it { is_expected.to validate_presence_of(:url) }
   
context "url format" do describe 'url' do
it { is_expected.to allow_value("http://example.com").for(:url) } it { is_expected.to allow_value("http://example.com").for(:url) }
it { is_expected.to allow_value("https://excample.com").for(:url) } it { is_expected.to allow_value("https://example.com").for(:url) }
it { is_expected.to allow_value(" https://example.com ").for(:url) }
it { is_expected.to allow_value("http://test.com/api").for(:url) } it { is_expected.to allow_value("http://test.com/api").for(:url) }
it { is_expected.to allow_value("http://test.com/api?key=abc").for(:url) } it { is_expected.to allow_value("http://test.com/api?key=abc").for(:url) }
it { is_expected.to allow_value("http://test.com/api?key=abc&type=def").for(:url) } it { is_expected.to allow_value("http://test.com/api?key=abc&type=def").for(:url) }
Loading
@@ -39,6 +33,12 @@ describe ProjectHook, models: true do
Loading
@@ -39,6 +33,12 @@ describe ProjectHook, models: true do
it { is_expected.not_to allow_value("example.com").for(:url) } it { is_expected.not_to allow_value("example.com").for(:url) }
it { is_expected.not_to allow_value("ftp://example.com").for(:url) } it { is_expected.not_to allow_value("ftp://example.com").for(:url) }
it { is_expected.not_to allow_value("herp-and-derp").for(:url) } it { is_expected.not_to allow_value("herp-and-derp").for(:url) }
it 'strips :url before saving it' do
hook = create(:project_hook, url: ' https://example.com ')
expect(hook.url).to eq('https://example.com')
end
end end
end end
   
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment