mirror of
https://github.com/neocities/neocities.git
synced 2025-04-25 01:32:36 +02:00
Fix stats for paths with spaces in them
This commit is contained in:
parent
93b5b94f14
commit
9affb83a2c
2 changed files with 26 additions and 1 deletions
|
@ -20,7 +20,20 @@ class Stat < Sequel::Model
|
|||
logfile = File.open log_path, 'r'
|
||||
|
||||
while hit = logfile.gets
|
||||
time, username, size, path, ip, referrer = hit.split ' '
|
||||
hit_array = hit.split ' '
|
||||
|
||||
# If > 6, then the path has a space in it, combine.
|
||||
if hit_array.length > 6
|
||||
time = hit_array[0]
|
||||
username = hit_array[1]
|
||||
size = hit_array[2]
|
||||
path_end_length = 3 + (hit_array.length - 6)
|
||||
path = hit_array[3..path_end_length].join ' '
|
||||
ip = hit_array[path_end_length+1]
|
||||
referrer = hit_array[path_end_length+2]
|
||||
else
|
||||
time, username, size, path, ip, referrer = hit_array
|
||||
end
|
||||
|
||||
next if !referrer.nil? && referrer.match(/bot/i)
|
||||
|
||||
|
|
|
@ -27,6 +27,18 @@ describe 'stats' do
|
|||
end
|
||||
end
|
||||
|
||||
it 'deals with spaces in paths' do
|
||||
@site = Fabricate :site
|
||||
File.open("tests/stat_logs/#{SecureRandom.uuid}.log", 'w') do |file|
|
||||
file.write "2015-05-02T21:16:35+00:00 #{@site.username} 612917 /images/derpie space.png 67.180.75.140 http://derp.com\n"
|
||||
end
|
||||
|
||||
Stat.parse_logfiles STAT_LOGS_PATH
|
||||
@site.stats.first.bandwidth.must_equal 612917
|
||||
@site.stat_referrers.first.url.must_equal 'http://derp.com'
|
||||
@site.stat_locations.first.city_name.must_equal 'Menlo Park'
|
||||
end
|
||||
|
||||
it 'prunes logs for free sites' do
|
||||
@free_site = Fabricate :site
|
||||
@supporter_site = Fabricate :site, plan_type: 'supporter'
|
||||
|
|
Loading…
Add table
Reference in a new issue