mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
check tag input
This commit is contained in:
parent
6444fe7e94
commit
9800a4ad4b
3 changed files with 3 additions and 2 deletions
|
@ -4,7 +4,7 @@ get '/browse/?' do
|
|||
@page = params[:page]
|
||||
@page = 1 if @page.not_an_integer?
|
||||
|
||||
params.delete 'tag' if params[:tag].nil? || params[:tag].strip.empty?
|
||||
params.delete 'tag' if params[:tag].nil? || !params[:tag].is_a?(String) || params[:tag].strip.empty? || params[:tag].match?(Tag::INVALID_TAG_REGEX)
|
||||
|
||||
if is_education?
|
||||
ds = education_sites_dataset
|
||||
|
|
|
@ -1093,7 +1093,7 @@ class Site < Sequel::Model
|
|||
|
||||
new_tags.each do |tag|
|
||||
tag.strip!
|
||||
if tag.match(/[^a-zA-Z0-9 ]/)
|
||||
if tag.match(Tag::INVALID_TAG_REGEX)
|
||||
errors.add :new_tags_string, "Tag \"#{tag}\" can only contain letters (A-Z) and numbers (0-9)."
|
||||
break
|
||||
end
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
class Tag < Sequel::Model
|
||||
NAME_LENGTH_MAX = 25
|
||||
NAME_WORDS_MAX = 1
|
||||
INVALID_TAG_REGEX = /[^a-zA-Z0-9 ]/
|
||||
many_to_many :sites
|
||||
|
||||
def before_create
|
||||
|
|
Loading…
Add table
Reference in a new issue