diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9d7a130..8ce5ee9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,4 +1,4 @@ -name: Deploy production to Heroku +name: Rubocop Linter on: push: branches: diff --git a/app/models/link.rb b/app/models/link.rb index 98df1d7..497da7f 100644 --- a/app/models/link.rb +++ b/app/models/link.rb @@ -1,11 +1,14 @@ # frozen_string_literal: true +VALID_URL_REGEX = /\A(?:https?:\/\/)?(?:[^@\n]+@)?(?:www\.)? \ + ([a-zA-Z0-9-]+\.[a-zA-Z]{2,}(?:\.[a-zA-Z]{2,})?) \ + (?:\/[^\s]*)?\z/ + class Link < ApplicationRecord validates :url, presence: true validates :slug, uniqueness: true - validates :url, - format: { with: /\A#{URI::DEFAULT_PARSER.make_regexp(%w[http https])}\z/, message: 'invalid format' } + validates :url, format: { with: VALID_URL_REGEX, message: 'invalid format' } validates :url, length: { within: 3..30_000, on: :create, message: 'max length is 30000' } before_validation :generate_slug diff --git a/app/views/links/_form.html.erb b/app/views/links/_form.html.erb index d3da99b..f9d9d32 100644 --- a/app/views/links/_form.html.erb +++ b/app/views/links/_form.html.erb @@ -4,11 +4,11 @@ Shorten an url