Skip to content

Commit

Permalink
Add social link validation for GitHub, GitLab, and Git URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew committed Jan 22, 2024
1 parent 6152d6d commit 6e0bd03
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/models/collective.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ def project_url
return "https://github.com/#{github}" if github.present?
return repository_url if repository_url.present?
social_link =(social_links || {}).select{|x| ['GITHUB', 'GITLAB', 'GIT'].include? x['type']}.first.try(:[], 'url')

# validate social link (path should start with a letter)
# TODO sr.ht slugs start with ~
if social_link.present?
uri = URI.parse(social_link)
social_link = nil unless uri.path.match(/\/[a-zA-Z]/)
end

return social_link if social_link.present?

# check if website is a github repo
Expand Down

0 comments on commit 6e0bd03

Please sign in to comment.