Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Remove fixture files with Windows incompatible filenames

Windows doesn't allow `\ / : * ? " < > |` in filenames so create
the fixture files at runtime and ignore the incompatible ones when
running on Windows.
  • Loading branch information...
commit 41c182c368eded5b62eb1f4945aa7e090bf2b811 1 parent b2e9bbd
Andrew White authored
115  actionpack/test/dispatch/static_test.rb
... ...
@@ -1,4 +1,5 @@
1 1
 require 'abstract_unit'
  2
+require 'rbconfig'
2 3
 
3 4
 module StaticTests
4 5
   def test_serves_dynamic_content
@@ -30,32 +31,84 @@ def test_serves_static_index_file_in_directory
30 31
     assert_html "/foo/index.html", get("/foo")
31 32
   end
32 33
 
33  
-  def test_serves_static_file_with_encoded_pchar
34  
-    assert_html "/foo/foo!bar.html", get("/foo/foo%21bar.html")
35  
-    assert_html "/foo/foo$bar.html", get("/foo/foo%24bar.html")
36  
-    assert_html "/foo/foo&bar.html", get("/foo/foo%26bar.html")
37  
-    assert_html "/foo/foo'bar.html", get("/foo/foo%27bar.html")
38  
-    assert_html "/foo/foo(bar).html", get("/foo/foo%28bar%29.html")
39  
-    assert_html "/foo/foo*bar.html", get("/foo/foo%2Abar.html")
40  
-    assert_html "/foo/foo+bar.html", get("/foo/foo%2Bbar.html")
41  
-    assert_html "/foo/foo,bar.html", get("/foo/foo%2Cbar.html")
42  
-    assert_html "/foo/foo;bar.html", get("/foo/foo%3Bbar.html")
43  
-    assert_html "/foo/foo:bar.html", get("/foo/foo%3Abar.html")
44  
-    assert_html "/foo/foo@bar.html", get("/foo/foo%40bar.html")
45  
-  end
46  
-
47  
-  def test_serves_static_file_with_unencoded_pchar
48  
-    assert_html "/foo/foo!bar.html", get("/foo/foo!bar.html")
49  
-    assert_html "/foo/foo$bar.html", get("/foo/foo$bar.html")
50  
-    assert_html "/foo/foo&bar.html", get("/foo/foo&bar.html")
51  
-    assert_html "/foo/foo'bar.html", get("/foo/foo'bar.html")
52  
-    assert_html "/foo/foo(bar).html", get("/foo/foo(bar).html")
53  
-    assert_html "/foo/foo*bar.html", get("/foo/foo*bar.html")
54  
-    assert_html "/foo/foo+bar.html", get("/foo/foo+bar.html")
55  
-    assert_html "/foo/foo,bar.html", get("/foo/foo,bar.html")
56  
-    assert_html "/foo/foo;bar.html", get("/foo/foo;bar.html")
57  
-    assert_html "/foo/foo:bar.html", get("/foo/foo:bar.html")
58  
-    assert_html "/foo/foo@bar.html", get("/foo/foo@bar.html")
  34
+  def test_serves_static_file_with_exclamation_mark_in_filename
  35
+    with_static_file "/foo/foo!bar.html" do |file|
  36
+      assert_html file, get("/foo/foo%21bar.html")
  37
+      assert_html file, get("/foo/foo!bar.html")
  38
+    end
  39
+  end
  40
+
  41
+  def test_serves_static_file_with_dollar_sign_in_filename
  42
+    with_static_file "/foo/foo$bar.html" do |file|
  43
+      assert_html file, get("/foo/foo%24bar.html")
  44
+      assert_html file, get("/foo/foo$bar.html")
  45
+    end
  46
+  end
  47
+
  48
+  def test_serves_static_file_with_ampersand_in_filename
  49
+    with_static_file "/foo/foo&bar.html" do |file|
  50
+      assert_html file, get("/foo/foo%26bar.html")
  51
+      assert_html file, get("/foo/foo&bar.html")
  52
+    end
  53
+  end
  54
+
  55
+  def test_serves_static_file_with_apostrophe_in_filename
  56
+    with_static_file "/foo/foo'bar.html" do |file|
  57
+      assert_html file, get("/foo/foo%27bar.html")
  58
+      assert_html file, get("/foo/foo'bar.html")
  59
+    end
  60
+  end
  61
+
  62
+  def test_serves_static_file_with_parentheses_in_filename
  63
+    with_static_file "/foo/foo(bar).html" do |file|
  64
+      assert_html file, get("/foo/foo%28bar%29.html")
  65
+      assert_html file, get("/foo/foo(bar).html")
  66
+    end
  67
+  end
  68
+
  69
+  def test_serves_static_file_with_plus_sign_in_filename
  70
+    with_static_file "/foo/foo+bar.html" do |file|
  71
+      assert_html file, get("/foo/foo%2Bbar.html")
  72
+      assert_html file, get("/foo/foo+bar.html")
  73
+    end
  74
+  end
  75
+
  76
+  def test_serves_static_file_with_comma_in_filename
  77
+    with_static_file "/foo/foo,bar.html" do |file|
  78
+      assert_html file, get("/foo/foo%2Cbar.html")
  79
+      assert_html file, get("/foo/foo,bar.html")
  80
+    end
  81
+  end
  82
+
  83
+  def test_serves_static_file_with_semi_colon_in_filename
  84
+    with_static_file "/foo/foo;bar.html" do |file|
  85
+      assert_html file, get("/foo/foo%3Bbar.html")
  86
+      assert_html file, get("/foo/foo;bar.html")
  87
+    end
  88
+  end
  89
+
  90
+  def test_serves_static_file_with_at_symbol_in_filename
  91
+    with_static_file "/foo/foo@bar.html" do |file|
  92
+      assert_html file, get("/foo/foo%40bar.html")
  93
+      assert_html file, get("/foo/foo@bar.html")
  94
+    end
  95
+  end
  96
+
  97
+  # Windows doesn't allow \ / : * ? " < > | in filenames
  98
+  unless RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
  99
+    def test_serves_static_file_with_colon
  100
+      with_static_file "/foo/foo:bar.html" do |file|
  101
+        assert_html file, get("/foo/foo%3Abar.html")
  102
+        assert_html file, get("/foo/foo:bar.html")
  103
+      end
  104
+    end
  105
+
  106
+    def test_serves_static_file_with_asterisk
  107
+      with_static_file "/foo/foo*bar.html" do |file|
  108
+        assert_html file, get("/foo/foo%2Abar.html")
  109
+        assert_html file, get("/foo/foo*bar.html")
  110
+      end
  111
+    end
59 112
   end
60 113
 
61 114
   private
@@ -68,6 +121,14 @@ def assert_html(body, response)
68 121
     def get(path)
69 122
       Rack::MockRequest.new(@app).request("GET", path)
70 123
     end
  124
+
  125
+    def with_static_file(file)
  126
+      path = "#{FIXTURE_LOAD_PATH}/public" + file
  127
+      File.open(path, "wb+") { |f| f.write(file) }
  128
+      yield file
  129
+    ensure
  130
+      File.delete(path)
  131
+    end
71 132
 end
72 133
 
73 134
 class StaticTest < ActiveSupport::TestCase
@@ -81,4 +142,4 @@ def setup
81 142
   end
82 143
 
83 144
   include StaticTests
84  
-end
  145
+end
1  actionpack/test/fixtures/public/foo/foo!bar.html
... ...
@@ -1 +0,0 @@
1  
-/foo/foo!bar.html
1  actionpack/test/fixtures/public/foo/foo$bar.html
... ...
@@ -1 +0,0 @@
1  
-/foo/foo$bar.html
1  actionpack/test/fixtures/public/foo/foo&bar.html
... ...
@@ -1 +0,0 @@
1  
-/foo/foo&bar.html
1  actionpack/test/fixtures/public/foo/foo'bar.html
... ...
@@ -1 +0,0 @@
1  
-/foo/foo'bar.html
1  actionpack/test/fixtures/public/foo/foo(bar).html
... ...
@@ -1 +0,0 @@
1  
-/foo/foo(bar).html
1  actionpack/test/fixtures/public/foo/foo*bar.html
... ...
@@ -1 +0,0 @@
1  
-/foo/foo*bar.html
1  actionpack/test/fixtures/public/foo/foo+bar.html
... ...
@@ -1 +0,0 @@
1  
-/foo/foo+bar.html
1  actionpack/test/fixtures/public/foo/foo,bar.html
... ...
@@ -1 +0,0 @@
1  
-/foo/foo,bar.html
1  actionpack/test/fixtures/public/foo/foo:bar.html
... ...
@@ -1 +0,0 @@
1  
-/foo/foo:bar.html
1  actionpack/test/fixtures/public/foo/foo;bar.html
... ...
@@ -1 +0,0 @@
1  
-/foo/foo;bar.html
1  actionpack/test/fixtures/public/foo/foo=bar.html
... ...
@@ -1 +0,0 @@
1  
-/foo/foo=bar.html
1  actionpack/test/fixtures/public/foo/foo@bar.html
... ...
@@ -1 +0,0 @@
1  
-/foo/foo@bar.html

0 notes on commit 41c182c

Please sign in to comment.
Something went wrong with that request. Please try again.