mirror of
https://github.com/neocities/neocities.git
synced 2025-04-25 01:32:36 +02:00
catch for bad strings before validation
This commit is contained in:
parent
7d43dbae19
commit
b122d54f1b
1 changed files with 19 additions and 2 deletions
|
@ -14,7 +14,15 @@ post '/create_validate_all' do
|
||||||
content_type :json
|
content_type :json
|
||||||
fields = params.select {|p| p.match CREATE_MATCH_REGEX}
|
fields = params.select {|p| p.match CREATE_MATCH_REGEX}
|
||||||
|
|
||||||
site = Site.new fields
|
begin
|
||||||
|
site = Site.new fields
|
||||||
|
rescue ArgumentError => e
|
||||||
|
if e.message == 'input string invalid'
|
||||||
|
return {error: 'invalid input'}.to_json
|
||||||
|
else
|
||||||
|
raise e
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if site.valid?
|
if site.valid?
|
||||||
return [].to_json if education_whitelisted?
|
return [].to_json if education_whitelisted?
|
||||||
|
@ -32,7 +40,16 @@ post '/create_validate' do
|
||||||
return {error: 'not a valid field'}.to_json
|
return {error: 'not a valid field'}.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
site = Site.new(params[:field] => params[:value])
|
begin
|
||||||
|
site = Site.new(params[:field] => params[:value])
|
||||||
|
rescue ArgumentError => e
|
||||||
|
if e.message == 'input string invalid'
|
||||||
|
return {error: 'invalid input'}.to_json
|
||||||
|
else
|
||||||
|
raise e
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
site.is_education = params[:is_education]
|
site.is_education = params[:is_education]
|
||||||
site.valid?
|
site.valid?
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue