Skip to content

Commit 2726945

Browse files
authored
fix: VCS regex matches all valid usernames for each provider; URLs are now case-insensitive, dokku check extended (#485)
* fixed vcs regex to allow upper case added a extra test to vcs links to test upper case links. also made it so portfolio links ands vcs links are stored in lower case * fixed houndci complaints * lossened username regex and add another test * made regex more pleasing to read * made regex method more readable * checks now does 300 attempts
1 parent 330325c commit 2726945

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

CHECKS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
WAIT=10
2-
ATTEMPTS=20
2+
ATTEMPTS=300
33

44
/users/sign_in Sign in to

app/models/questionnaire.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ class Questionnaire < ApplicationRecord
4343

4444
validates :portfolio_url, url: { allow_blank: true }
4545
validates :vcs_url, url: { allow_blank: true }
46-
validates_format_of :vcs_url, with: %r{\A(((https?:\/\/)?(www\.)?github\.com\/\w+\/?)|((https?:\/\/)?(www\.)?gitlab\.com\/\w+\/?)|((https?:\/\/)?(www\.)?bitbucket\.org\/\w+\/?))\z}, allow_blank: true, message: "Must be a GitHub, GitLab or Bitbucket url"
46+
validates_format_of :vcs_url,
47+
with: %r{\A((https?:\/\/)?(www\.)?((github\.com)|(gitlab\.com)|(bitbucket\.org))\/(.*){0,62})\z}i,
48+
allow_blank: true,
49+
message: "Must be a GitHub, GitLab or Bitbucket url"
4750
strip_attributes
4851

4952
POSSIBLE_EXPERIENCES = {
@@ -129,11 +132,13 @@ def email
129132
end
130133

131134
def portfolio_url=(value)
135+
value = value.downcase unless value.blank?
132136
value = "http://" + value if !value.blank? && !value.include?("http://") && !value.include?("https://")
133137
super value
134138
end
135139

136140
def vcs_url=(value)
141+
value = value.downcase unless value.blank?
137142
value = "https://" + value if !value.blank? && !value.include?("http://") && !value.include?("https://")
138143
super value
139144
end

test/models/questionnaire_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ class QuestionnaireTest < ActiveSupport::TestCase
103103
should allow_value('foo.com').for(:portfolio_url)
104104
should allow_value('github.com/foo', 'gitlab.com/bar', 'bitbucket.org/baz').for(:vcs_url)
105105
should allow_value('https://github.com/foo', 'https://gitlab.com/bar', 'https://bitbucket.org/baz').for(:vcs_url)
106+
should allow_value('HttPs://gITHub.CoM/foo', 'hTTp://gitLAB.coM/bar').for(:vcs_url)
107+
should allow_value('wWw.gITHub.CoM/fOo', 'hTTp://wWw.gitLAB.coM/f-fc-vx').for(:vcs_url)
106108
should_not allow_value('http://foo.com', 'https://bar.com').for(:vcs_url)
107109

108110
context "#school" do

0 commit comments

Comments
 (0)