mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
more strict integer checks
This commit is contained in:
parent
1d87b87e62
commit
f7e65ec61b
10 changed files with 30 additions and 21 deletions
|
@ -1,13 +1,8 @@
|
||||||
get '/browse/?' do
|
get '/browse/?' do
|
||||||
@surfmode = false
|
@surfmode = false
|
||||||
|
|
||||||
begin
|
@page = params[:page]
|
||||||
@page = params[:page].to_i
|
@page = 1 if @page.not_an_integer?
|
||||||
rescue
|
|
||||||
@page = 1
|
|
||||||
end
|
|
||||||
|
|
||||||
@page = 1 if @page == 0
|
|
||||||
|
|
||||||
params.delete 'tag' if params[:tag].nil? || params[:tag].strip.empty?
|
params.delete 'tag' if params[:tag].nil? || params[:tag].strip.empty?
|
||||||
|
|
||||||
|
@ -17,7 +12,7 @@ get '/browse/?' do
|
||||||
ds = browse_sites_dataset
|
ds = browse_sites_dataset
|
||||||
end
|
end
|
||||||
|
|
||||||
ds = ds.paginate @page, Site::BROWSE_PAGINATION_LENGTH
|
ds = ds.paginate @page.to_i, Site::BROWSE_PAGINATION_LENGTH
|
||||||
@pagination_dataset = ds
|
@pagination_dataset = ds
|
||||||
@sites = ds.all
|
@sites = ds.all
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,8 @@ get '/?' do
|
||||||
|
|
||||||
redirect '/dashboard' if current_site.is_education
|
redirect '/dashboard' if current_site.is_education
|
||||||
|
|
||||||
@page = params[:page].to_i
|
@page = params[:page]
|
||||||
@page = 1 if @page == 0
|
@page = 1 if @page.not_an_integer?
|
||||||
|
|
||||||
if params[:activity] == 'mine'
|
if params[:activity] == 'mine'
|
||||||
events_dataset = current_site.latest_events(@page, 10)
|
events_dataset = current_site.latest_events(@page, 10)
|
||||||
|
|
|
@ -17,12 +17,10 @@ get '/site/:username/?' do |username|
|
||||||
@title = site.title
|
@title = site.title
|
||||||
|
|
||||||
@page = params[:page]
|
@page = params[:page]
|
||||||
@page = @page.to_i
|
@page = 1 if @page.not_an_integer?
|
||||||
@page = 1 if @page == 0
|
|
||||||
|
|
||||||
if params[:event_id]
|
if params[:event_id]
|
||||||
not_found if params[:event_id].is_a?(Array)
|
not_found if params[:event_id].not_an_integer?
|
||||||
not_found unless params[:event_id].to_i > 0
|
|
||||||
event = Event.select(:id).where(id: params[:event_id]).first
|
event = Event.select(:id).where(id: params[:event_id]).first
|
||||||
not_found if event.nil?
|
not_found if event.nil?
|
||||||
events_dataset = Event.where(id: params[:event_id]).paginate(1, 1)
|
events_dataset = Event.where(id: params[:event_id]).paginate(1, 1)
|
||||||
|
@ -84,7 +82,7 @@ get '/site/:username/stats' do
|
||||||
|
|
||||||
if @site.supporter?
|
if @site.supporter?
|
||||||
unless params[:days].to_s == 'sincethebigbang'
|
unless params[:days].to_s == 'sincethebigbang'
|
||||||
if params[:days] && params[:days].to_i != 0
|
unless params[:days].not_an_integer?
|
||||||
stats_dataset = stats_dataset.limit params[:days]
|
stats_dataset = stats_dataset.limit params[:days]
|
||||||
else
|
else
|
||||||
params[:days] = @default_stat_points
|
params[:days] = @default_stat_points
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
get '/surf/?' do
|
get '/surf/?' do
|
||||||
not_found # 404 for now
|
not_found # 404 for now
|
||||||
@page = params[:page].to_i || 1
|
@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].strip.empty?
|
||||||
site_dataset = browse_sites_dataset
|
site_dataset = browse_sites_dataset
|
||||||
site_dataset = site_dataset.paginate @page, 1
|
site_dataset = site_dataset.paginate @page.to_i, 1
|
||||||
@page_count = site_dataset.page_count || 1
|
@page_count = site_dataset.page_count || 1
|
||||||
@site = site_dataset.first
|
@site = site_dataset.first
|
||||||
redirect "/browse?#{Rack::Utils.build_query params}" if @site.nil?
|
redirect "/browse?#{Rack::Utils.build_query params}" if @site.nil?
|
||||||
|
|
|
@ -143,7 +143,7 @@ def stripe_get_site_from_event(event)
|
||||||
site_where = {username: desc_split.first}
|
site_where = {username: desc_split.first}
|
||||||
end
|
end
|
||||||
|
|
||||||
if desc_split.last.to_i == 0
|
if desc_split.last.not_an_integer?
|
||||||
site_where = {username: desc_split.first}
|
site_where = {username: desc_split.first}
|
||||||
else
|
else
|
||||||
site_where = {id: desc_split.last}
|
site_where = {id: desc_split.last}
|
||||||
|
|
|
@ -6,4 +6,8 @@ class NilClass
|
||||||
def blank?
|
def blank?
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def not_an_integer?
|
||||||
|
true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -76,4 +76,8 @@ class Numeric
|
||||||
def to_space_pretty
|
def to_space_pretty
|
||||||
to_bytes_pretty
|
to_bytes_pretty
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def not_an_integer?
|
||||||
|
!self.integer?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,4 +16,11 @@ class String
|
||||||
return true if self == ''
|
return true if self == ''
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def not_an_integer?
|
||||||
|
Integer(self)
|
||||||
|
false
|
||||||
|
rescue ArgumentError
|
||||||
|
true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -50,7 +50,7 @@ class Event < Sequel::Model
|
||||||
|
|
||||||
def self.global_dataset(current_page=1, limit=DEFAULT_GLOBAL_LIMIT)
|
def self.global_dataset(current_page=1, limit=DEFAULT_GLOBAL_LIMIT)
|
||||||
news_feed_default_dataset.
|
news_feed_default_dataset.
|
||||||
paginate(current_page, 100).
|
paginate(current_page.to_i, 100).
|
||||||
exclude(is_nsfw: true).
|
exclude(is_nsfw: true).
|
||||||
exclude(is_crashing: true).
|
exclude(is_crashing: true).
|
||||||
where{views > GLOBAL_VIEWS_MINIMUM}.
|
where{views > GLOBAL_VIEWS_MINIMUM}.
|
||||||
|
|
|
@ -1350,7 +1350,7 @@ class Site < Sequel::Model
|
||||||
site_id = self.id
|
site_id = self.id
|
||||||
Event.news_feed_default_dataset.where{Sequel.|({site_id: site_id}, {actioning_site_id: site_id})}.
|
Event.news_feed_default_dataset.where{Sequel.|({site_id: site_id}, {actioning_site_id: site_id})}.
|
||||||
order(:created_at.desc).
|
order(:created_at.desc).
|
||||||
paginate(current_page, limit)
|
paginate(current_page.to_i, limit.to_i)
|
||||||
end
|
end
|
||||||
|
|
||||||
def news_feed(current_page=1, limit=10)
|
def news_feed(current_page=1, limit=10)
|
||||||
|
@ -1359,7 +1359,7 @@ class Site < Sequel::Model
|
||||||
|
|
||||||
Event.news_feed_default_dataset.where{Sequel.|({site_id: search_ids}, {actioning_site_id: search_ids})}.
|
Event.news_feed_default_dataset.where{Sequel.|({site_id: search_ids}, {actioning_site_id: search_ids})}.
|
||||||
order(:created_at.desc).
|
order(:created_at.desc).
|
||||||
paginate(current_page, limit)
|
paginate(current_page.to_i, limit.to_i)
|
||||||
end
|
end
|
||||||
|
|
||||||
def newest_follows
|
def newest_follows
|
||||||
|
|
Loading…
Add table
Reference in a new issue