Imports changes from Rails' revision r9070
| 306 | gsub(%r{(.)[\\/]$}, '\1') # drop final / or \ if path ends with it | gsub(%r{(.)[\\/]$}, '\1') # drop final / or \ if path ends with it | 306 |
|---|---|---|---|
| 307 | 307 | ||
| 308 | # eliminate .. paths where possible | # eliminate .. paths where possible | 308 |
| 309 | re = %r{\w+[/\\]\.\.[/\\]} | re = %r{[^/\\]+[/\\]\.\.[/\\]} | 309 |
| 310 | path.gsub!(%r{\w+[/\\]\.\.[/\\]}, "") while path.match(re) | path.gsub!(re, "") while path.match(re) | 310 |
| 311 | path | path | 311 |
| 312 | end | end | 312 |
| 313 | 313 |
| 2119 | end | end | 2119 |
|---|---|---|---|
| 2120 | 2120 | ||
| 2121 | def test_normalize_unix_paths | def test_normalize_unix_paths | 2121 |
| 2122 | load_paths = %w(. config/../app/controllers config/../app//helpers script/../config/../vendor/rails/actionpack/lib vendor/rails/railties/builtin/rails_info app/models lib script/../config/../foo/bar/../../app/models) | load_paths = %w(. config/../app/controllers config/../app//helpers script/../config/../vendor/rails/actionpack/lib vendor/rails/railties/builtin/rails_info app/models lib script/../config/../foo/bar/../../app/models .foo/../.bar foo.bar/../config) | 2122 |
| 2123 | paths = ActionController::Routing.normalize_paths(load_paths) | paths = ActionController::Routing.normalize_paths(load_paths) | 2123 |
| 2124 | assert_equal %w(vendor/rails/railties/builtin/rails_info vendor/rails/actionpack/lib app/controllers app/helpers app/models lib .), paths | assert_equal %w(vendor/rails/railties/builtin/rails_info vendor/rails/actionpack/lib app/controllers app/helpers app/models config .bar lib .), paths | 2124 |
| 2125 | end | end | 2125 |
| 2126 | 2126 | ||
| 2127 | def test_normalize_windows_paths | def test_normalize_windows_paths | 2127 |
| 2128 | load_paths = %w(. config\\..\\app\\controllers config\\..\\app\\\\helpers script\\..\\config\\..\\vendor\\rails\\actionpack\\lib vendor\\rails\\railties\\builtin\\rails_info app\\models lib script\\..\\config\\..\\foo\\bar\\..\\..\\app\\models) | load_paths = %w(. config\\..\\app\\controllers config\\..\\app\\\\helpers script\\..\\config\\..\\vendor\\rails\\actionpack\\lib vendor\\rails\\railties\\builtin\\rails_info app\\models lib script\\..\\config\\..\\foo\\bar\\..\\..\\app\\models .foo\\..\\.bar foo.bar\\..\\config) | 2128 |
| 2129 | paths = ActionController::Routing.normalize_paths(load_paths) | paths = ActionController::Routing.normalize_paths(load_paths) | 2129 |
| 2130 | assert_equal %w(vendor\\rails\\railties\\builtin\\rails_info vendor\\rails\\actionpack\\lib app\\controllers app\\helpers app\\models lib .), paths | assert_equal %w(vendor\\rails\\railties\\builtin\\rails_info vendor\\rails\\actionpack\\lib app\\controllers app\\helpers app\\models config .bar lib .), paths | 2130 |
| 2131 | end | end | 2131 |
| 2132 | 2132 | ||
| 2133 | def test_routing_helper_module | def test_routing_helper_module | 2133 |