Update profile links regex to allow trailing slash (#614)

* Update url validation specs to include multiple cases of usernames

* Allow trailing slash in profile links

* Add username with dot separators to list of valid fb usernames

* Update fb url regex to allow dots in between words

* Push existing fb regex allowing for dot separators

* Revert to old regex with added period to character class

* Revert length restriction on fb regex
This commit is contained in:
Timothy Ng 2018-09-10 13:34:45 -07:00 committed by Ben Halpern
parent b2dc1f2b7e
commit b32ebdb9b9
2 changed files with 25 additions and 15 deletions

View file

@ -56,22 +56,22 @@ class User < ApplicationRecord
validates :website_url, url: { allow_blank: true, no_local: true, schemes: ["https", "http"] }
# rubocop:disable Metrics/LineLength
validates :facebook_url,
format: /\Ahttps:\/\/(www.facebook.com|facebook.com)\/([a-zA-Z0-9]{5,50})\Z/,
format: /\Ahttps:\/\/(www.facebook.com|facebook.com)\/[a-zA-Z0-9.]{5,50}\/?\Z/,
allow_blank: true
validates :stackoverflow_url,
allow_blank: true,
format:
/\Ahttps:\/\/(www.stackoverflow.com|stackoverflow.com)\/users\/([0-9]{3,10})\/([a-zA-Z0-9\s\'\-]{3,30})\Z/
/\Ahttps:\/\/(www.stackoverflow.com|stackoverflow.com)\/users\/([0-9]{3,10})\/([a-zA-Z0-9\s\'\-]{3,30})\/?\Z/
validates :behance_url,
allow_blank: true,
format: /\Ahttps:\/\/(www.behance.net|behance.net)\/([a-zA-Z0-9\-\_]{3,20})\Z/
format: /\Ahttps:\/\/(www.behance.net|behance.net)\/([a-zA-Z0-9\-\_]{3,20})\/?\Z/
validates :linkedin_url,
allow_blank: true,
format:
/\Ahttps:\/\/(www.linkedin.com|linkedin.com|[A-Za-z]{2}.linkedin.com)\/in\/([a-zA-Z0-9\-]{3,100})\Z/
/\Ahttps:\/\/(www.linkedin.com|linkedin.com|[A-Za-z]{2}.linkedin.com)\/in\/([a-zA-Z0-9\-]{3,100})\/?\Z/
validates :dribbble_url,
allow_blank: true,
format: /\Ahttps:\/\/(www.dribbble.com|dribbble.com)\/([a-zA-Z0-9\-\_]{2,20})\Z/
format: /\Ahttps:\/\/(www.dribbble.com|dribbble.com)\/([a-zA-Z0-9\-\_]{2,20})\/?\Z/
# rubocop:enable Metrics/LineLength
validates :employer_url, url: { allow_blank: true, no_local: true, schemes: ["https", "http"] }
validates :shirt_gender,

View file

@ -66,8 +66,10 @@ RSpec.describe User, type: :model do
end
it "accepts valid https facebook url" do
user.facebook_url = "https://facebook.com/thepracticaldev"
expect(user).to be_valid
%w(thepracticaldev thepracticaldev/ the.practical.dev).each do |username|
user.facebook_url = "https://facebook.com/#{username}"
expect(user).to be_valid
end
end
it "does not accept invalid facebook url" do
@ -76,8 +78,10 @@ RSpec.describe User, type: :model do
end
it "accepts valid https behance url" do
user.behance_url = "https://behance.net/jess"
expect(user).to be_valid
%w(jess jess/ je-ss jes_ss).each do |username|
user.behance_url = "https://behance.net/#{username}"
expect(user).to be_valid
end
end
it "does not accept invalid behance url" do
@ -86,8 +90,10 @@ RSpec.describe User, type: :model do
end
it "accepts valid https stackoverflow url" do
user.stackoverflow_url = "https://stackoverflow.com/users/7381391/pandyzhao"
expect(user).to be_valid
%w(pandyzhao pandyzhao/ pandy-zhao).each do |username|
user.stackoverflow_url = "https://stackoverflow.com/users/7381391/#{username}"
expect(user).to be_valid
end
end
it "does not accept invalid stackoverflow url" do
@ -96,8 +102,10 @@ RSpec.describe User, type: :model do
end
it "accepts valid https linkedin url" do
user.linkedin_url = "https://linkedin.com/in/jessleenyc"
expect(user).to be_valid
%w(jessleenyc jessleenyc/ jess-lee-nyc).each do |username|
user.linkedin_url = "https://linkedin.com/in/#{username}"
expect(user).to be_valid
end
end
it "accepts valid country specific https linkedin url" do
@ -121,8 +129,10 @@ RSpec.describe User, type: :model do
end
it "accepts valid https dribbble url" do
user.dribbble_url = "https://dribbble.com/jess"
expect(user).to be_valid
%w(jess jess/ je-ss je_ss).each do |username|
user.dribbble_url = "https://dribbble.com/#{username}"
expect(user).to be_valid
end
end
it "does not accept invalid dribbble url" do