From 3cfadd5fa2306ec1f382343220805546e1444cd8 Mon Sep 17 00:00:00 2001 From: George Claghorn Date: Mon, 14 Aug 2017 16:04:11 -0400 Subject: Move test to its proper place ActiveStorage::Filename is a model, so its test case belongs in test/models. --- activestorage/test/filename_test.rb | 38 ------------------------------ activestorage/test/models/filename_test.rb | 38 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 38 deletions(-) delete mode 100644 activestorage/test/filename_test.rb create mode 100644 activestorage/test/models/filename_test.rb (limited to 'activestorage') diff --git a/activestorage/test/filename_test.rb b/activestorage/test/filename_test.rb deleted file mode 100644 index f1e4a467ba..0000000000 --- a/activestorage/test/filename_test.rb +++ /dev/null @@ -1,38 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -class ActiveStorage::FilenameTest < ActiveSupport::TestCase - test "sanitize" do - "%$|:;/\t\r\n\\".each_char do |character| - filename = ActiveStorage::Filename.new("foo#{character}bar.pdf") - assert_equal "foo-bar.pdf", filename.sanitized - assert_equal "foo-bar.pdf", filename.to_s - end - end - - test "sanitize transcodes to valid UTF-8" do - { "\xF6".dup.force_encoding(Encoding::ISO8859_1) => "ö", - "\xC3".dup.force_encoding(Encoding::ISO8859_1) => "Ã", - "\xAD" => "�", - "\xCF" => "�", - "\x00" => "", - }.each do |actual, expected| - assert_equal expected, ActiveStorage::Filename.new(actual).sanitized - end - end - - test "strips RTL override chars used to spoof unsafe executables as docs" do - # Would be displayed in Windows as "evilexe.pdf" due to the right-to-left - # (RTL) override char! - assert_equal "evil-fdp.exe", ActiveStorage::Filename.new("evil\u{202E}fdp.exe").sanitized - end - - test "compare case-insensitively" do - assert_operator ActiveStorage::Filename.new("foobar.pdf"), :==, ActiveStorage::Filename.new("FooBar.PDF") - end - - test "compare sanitized" do - assert_operator ActiveStorage::Filename.new("foo-bar.pdf"), :==, ActiveStorage::Filename.new("foo\tbar.pdf") - end -end diff --git a/activestorage/test/models/filename_test.rb b/activestorage/test/models/filename_test.rb new file mode 100644 index 0000000000..f1e4a467ba --- /dev/null +++ b/activestorage/test/models/filename_test.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +require "test_helper" + +class ActiveStorage::FilenameTest < ActiveSupport::TestCase + test "sanitize" do + "%$|:;/\t\r\n\\".each_char do |character| + filename = ActiveStorage::Filename.new("foo#{character}bar.pdf") + assert_equal "foo-bar.pdf", filename.sanitized + assert_equal "foo-bar.pdf", filename.to_s + end + end + + test "sanitize transcodes to valid UTF-8" do + { "\xF6".dup.force_encoding(Encoding::ISO8859_1) => "ö", + "\xC3".dup.force_encoding(Encoding::ISO8859_1) => "Ã", + "\xAD" => "�", + "\xCF" => "�", + "\x00" => "", + }.each do |actual, expected| + assert_equal expected, ActiveStorage::Filename.new(actual).sanitized + end + end + + test "strips RTL override chars used to spoof unsafe executables as docs" do + # Would be displayed in Windows as "evilexe.pdf" due to the right-to-left + # (RTL) override char! + assert_equal "evil-fdp.exe", ActiveStorage::Filename.new("evil\u{202E}fdp.exe").sanitized + end + + test "compare case-insensitively" do + assert_operator ActiveStorage::Filename.new("foobar.pdf"), :==, ActiveStorage::Filename.new("FooBar.PDF") + end + + test "compare sanitized" do + assert_operator ActiveStorage::Filename.new("foo-bar.pdf"), :==, ActiveStorage::Filename.new("foo\tbar.pdf") + end +end -- cgit v1.2.3