FROM HELL'S HEART, I STAB AT UTF-8

This commit is contained in:
Kyle Drake 2014-12-26 22:36:37 -06:00
parent 20f3e34d9c
commit 1b3d7f7933
3 changed files with 15 additions and 7 deletions

View file

@ -509,7 +509,7 @@ class Site < Sequel::Model
end
if pathname.extname.match EDITABLE_FILE_EXT
open(uploaded.path) {|f|
open(uploaded.path, 'r:binary') {|f|
matches = f.grep SPAM_MATCH_REGEX
if !matches.empty?
@ -520,10 +520,8 @@ class Site < Sequel::Model
subject: "[Neocities SPAM]: #{username}",
body: %{
#{username}
<br>
https://#{self.host}#{relative_path}
<br>
<a href="https://#{self.host}/#{relative_path}">link</a>
https://#{self.host}/#{relative_path}
Match: #{matches.first.strip}
}
})
end

View file

@ -0,0 +1,5 @@
<html>
<body>
hi ュ
</body>
</html>

View file

@ -34,6 +34,11 @@ describe 'site_files' do
end
describe 'upload' do
it 'manages files with invalid UTF8' do
upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/invalidutf8.html', 'text/html')
File.exists?(@site.files_path('invalidutf8.html')).must_equal true
end
it 'succeeds with index.html file' do
@site.site_changed.must_equal false
upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/index.html', 'text/html')
@ -67,12 +72,12 @@ describe 'site_files' do
it 'fails with unsupported file' do
upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/flowercrime.wav', 'audio/x-wav')
last_response.body.must_match /not allowed on this site/i
last_response.body.must_match /only supported by.+supporter account/i
File.exists?(@site.files_path('flowercrime.wav')).must_equal false
@site.site_changed.must_equal false
end
it 'succeeds for usually unsupported file on supported plans' do
it 'succeeds for unwhitelisted file on supporter plans' do
no_file_restriction_plans = Site::PLAN_FEATURES.select {|p,v| v[:no_file_restrictions] == true}
no_file_restriction_plans.each do |plan_type,hash|
@site = Fabricate :site, plan_type: plan_type