From 860e8b2ebdb0b47af15bf65d2fdacab425ae85b7 Mon Sep 17 00:00:00 2001 From: Paul Westcott Date: Wed, 25 May 2022 00:13:35 +1000 Subject: [PATCH] Restore the normalize check that appears to be inadvertantly removed (#1802) * Add test for normalize on upload Co-authored-by: Dawa Ometto --- lib/gollum/app.rb | 2 +- test/test_app.rb | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/gollum/app.rb b/lib/gollum/app.rb index 8b5a94e4..2546c4eb 100644 --- a/lib/gollum/app.rb +++ b/lib/gollum/app.rb @@ -273,7 +273,7 @@ module Precious options.merge! author end - normalize = Gollum::Page.valid_extension?(fullname) + options[:normalize] = Gollum::Page.valid_extension?(fullname) begin wiki.write_file(reponame, contents, options) diff --git a/test/test_app.rb b/test/test_app.rb index cb82c221..297e7709 100644 --- a/test/test_app.rb +++ b/test/test_app.rb @@ -477,9 +477,9 @@ EOF assert_equal 'abc', file.raw_data Precious::App.set(:wiki_options, {allow_uploads: false}) end - + test "upload a file with mode page" do - temp_upload_file = Tempfile.new(['upload', '.file']) << 'abc' + temp_upload_file = Tempfile.new(['upload', '.file']) << "abc\r" temp_upload_file.close Precious::App.set(:wiki_options, {allow_uploads: true, per_page_uploads: true}) post "/gollum/upload_file", {:file => Rack::Test::UploadedFile.new(::File.open(temp_upload_file))}, {'HTTP_REFERER' => 'http://localhost:4567/Home.md', 'HTTP_HOST' => 'localhost:4567'} @@ -488,7 +488,21 @@ EOF @wiki.clear_cache # Find the file in a page-specific subdir (here: Home), based on referer file = @wiki.file("uploads/Home/#{::File.basename(temp_upload_file.path)}") - assert_equal 'abc', file.raw_data + assert_equal "abc\r", file.raw_data + Precious::App.set(:wiki_options, {allow_uploads: false, per_page_uploads: false}) + end + + test "upload a file with valid extension" do + temp_upload_file = Tempfile.new(['upload', '.txt']) << "abc\r" + temp_upload_file.close + Precious::App.set(:wiki_options, {allow_uploads: true, per_page_uploads: true}) + post "/gollum/upload_file", {:file => Rack::Test::UploadedFile.new(::File.open(temp_upload_file))}, {'HTTP_REFERER' => 'http://localhost:4567/Home.md', 'HTTP_HOST' => 'localhost:4567'} + + assert_equal 302, last_response.status # redirect is expected + @wiki.clear_cache + # Find the file in a page-specific subdir (here: Home), based on referer + file = @wiki.file("uploads/Home/#{::File.basename(temp_upload_file.path)}") + assert_equal "abc", file.raw_data Precious::App.set(:wiki_options, {allow_uploads: false, per_page_uploads: false}) end