diff --git a/app.rb b/app.rb index cee003f5..7bdd2e77 100644 --- a/app.rb +++ b/app.rb @@ -35,8 +35,9 @@ get '/?' do end get '/browse' do - @current_page = params[:current_page] || 1 + @current_page = params[:current_page] @current_page = @current_page.to_i + @current_page = 1 if @current_page == 0 site_dataset = Site.filter(is_banned: false).filter(site_changed: true).paginate(@current_page, 300) @@ -605,3 +606,12 @@ end def template_site_title(username) "#{username.capitalize}#{username[username.length-1] == 's' ? "'" : "'s"} Site" end + +def encoding_fix(file) + begin + Rack::Utils.escape_html file + rescue ArgumentError => e + return Rack::Utils.escape_html(file.force_encoding('BINARY')) if e.message =~ /invalid byte sequence in UTF-8/ + fail + end +end diff --git a/models/site.rb b/models/site.rb index e7ad3252..8c98dcc3 100644 --- a/models/site.rb +++ b/models/site.rb @@ -1,7 +1,7 @@ class Site < Sequel::Model # We might need to include fonts in here.. - VALID_MIME_TYPES = ['text/plain', 'text/html', 'text/css', 'application/javascript', 'image/png', 'image/jpeg', 'image/gif', 'image/svg+xml', 'application/vnd.ms-fontobject', 'application/x-font-ttf', 'application/octet-stream', 'text/csv', 'text/tsv', 'text/cache-manifest'] - VALID_EXTENSIONS = %w{ html htm txt text css js jpg jpeg png gif svg md markdown eot ttf woff json geojson csv tsv mf} + VALID_MIME_TYPES = ['text/plain', 'text/html', 'text/css', 'application/javascript', 'image/png', 'image/jpeg', 'image/gif', 'image/svg+xml', 'application/vnd.ms-fontobject', 'application/x-font-ttf', 'application/octet-stream', 'text/csv', 'text/tsv', 'text/cache-manifest', 'image/x-icon'] + VALID_EXTENSIONS = %w{ html htm txt text css js jpg jpeg png gif svg md markdown eot ttf woff json geojson csv tsv mf ico} #USERNAME_SHITLIST = %w{ payment secure login signin www ww web } # I thought they were funny personally, but everybody is freaking out so.. MAX_SPACE = (5242880*2) # 10MB MINIMUM_PASSWORD_LENGTH = 5 diff --git a/views/site_files/text_editor.slim b/views/site_files/text_editor.slim index 5b2e4f8e..468352c5 100644 --- a/views/site_files/text_editor.slim +++ b/views/site_files/text_editor.slim @@ -56,7 +56,7 @@ css: .row .span12 div id="editor" style="width: 100%; height: 600px; position: relative;" - #{@file_data} + == encoding_fix @file_data .row diff --git a/views/site_files/upload.slim b/views/site_files/upload.slim index 46be1bde..3af1ebe1 100644 --- a/views/site_files/upload.slim +++ b/views/site_files/upload.slim @@ -43,7 +43,7 @@ javascript: .row .span5.text-center - h5 NeoCities uses a drop and drop file upload. Simply take files and drop them from your computer on the white box (or click it) and they are uploaded. + h5 NeoCities uses a "drag and drop" file upload. Simply take files and drop them from your computer on the white box (or click it) and they are uploaded. div style="background-color: #FFFFFF;" form action="/site_files/upload" class="dropzone" id="uploads" input name="csrf_token" type="hidden" value="#{csrf_token}"