mirror of
https://github.com/neocities/neocities.git
synced 2025-04-25 01:32:36 +02:00
FROM HELL'S HEART, I STAB AT UTF-8
This commit is contained in:
parent
20f3e34d9c
commit
1b3d7f7933
3 changed files with 15 additions and 7 deletions
|
@ -509,7 +509,7 @@ class Site < Sequel::Model
|
||||||
end
|
end
|
||||||
|
|
||||||
if pathname.extname.match EDITABLE_FILE_EXT
|
if pathname.extname.match EDITABLE_FILE_EXT
|
||||||
open(uploaded.path) {|f|
|
open(uploaded.path, 'r:binary') {|f|
|
||||||
matches = f.grep SPAM_MATCH_REGEX
|
matches = f.grep SPAM_MATCH_REGEX
|
||||||
|
|
||||||
if !matches.empty?
|
if !matches.empty?
|
||||||
|
@ -520,10 +520,8 @@ class Site < Sequel::Model
|
||||||
subject: "[Neocities SPAM]: #{username}",
|
subject: "[Neocities SPAM]: #{username}",
|
||||||
body: %{
|
body: %{
|
||||||
#{username}
|
#{username}
|
||||||
<br>
|
https://#{self.host}/#{relative_path}
|
||||||
https://#{self.host}#{relative_path}
|
Match: #{matches.first.strip}
|
||||||
<br>
|
|
||||||
<a href="https://#{self.host}/#{relative_path}">link</a>
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
5
tests/files/invalidutf8.html
Normal file
5
tests/files/invalidutf8.html
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
hi ュ
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -34,6 +34,11 @@ describe 'site_files' do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'upload' do
|
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
|
it 'succeeds with index.html file' do
|
||||||
@site.site_changed.must_equal false
|
@site.site_changed.must_equal false
|
||||||
upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/index.html', 'text/html')
|
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
|
it 'fails with unsupported file' do
|
||||||
upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/flowercrime.wav', 'audio/x-wav')
|
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
|
File.exists?(@site.files_path('flowercrime.wav')).must_equal false
|
||||||
@site.site_changed.must_equal false
|
@site.site_changed.must_equal false
|
||||||
end
|
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 = Site::PLAN_FEATURES.select {|p,v| v[:no_file_restrictions] == true}
|
||||||
no_file_restriction_plans.each do |plan_type,hash|
|
no_file_restriction_plans.each do |plan_type,hash|
|
||||||
@site = Fabricate :site, plan_type: plan_type
|
@site = Fabricate :site, plan_type: plan_type
|
||||||
|
|
Loading…
Add table
Reference in a new issue