rack-url-canonicalizer 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/rack/url_canonicalizer/configuration.rb +2 -0
- data/lib/rack/url_canonicalizer/version.rb +1 -1
- data/lib/rack/url_canonicalizer.rb +2 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 894b233627b42a6f6db8d6962f8622cd768b39603f1f569b79a45d413c89a95d
|
|
4
|
+
data.tar.gz: 1875213c68bdd7bb0cc6df9b84984117d98ef1d23a678c0c0268d3ee51690936
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d940708d8f98bf171dd7d4e8d521f131a1f85a58256dbcfb985551fc3aa0c61bd923da039e3a6cf5b1addc50e6c508f80f0eda4ac9045559fd58ef94912682e9
|
|
7
|
+
data.tar.gz: 1eea70a9bb3a300d90133749c1197cf06b492def21d9aa8f84b4fa823a483f37dd78ac57e76ee5699c5a9bbf23810d3712110dd0466f47689cce7c6194ddfc71
|
data/README.md
CHANGED
|
@@ -52,6 +52,7 @@ bundle install
|
|
|
52
52
|
| `downcase_path` | `Boolean` | `false` | Converts path to lowercase (e.g. `/About-Us` ➔ `/about-us`). Query string casing is preserved. |
|
|
53
53
|
| `downcase_paths` | `Array<String \| Regexp \| Proc> \| Boolean` | `nil` | Selective allowlist: only paths matching these prefixes or patterns are downcased. |
|
|
54
54
|
| `downcase_exclude_paths` | `Array<String \| Regexp \| Proc>` | `[]` | Array of path prefixes, patterns, or procs to bypass from downcasing (preserves casing for tokens/IDs). |
|
|
55
|
+
| `downcase_exclude_rails_paths` | `Boolean` | `true` | Automatically preserves casing for Rails internal routes (`/rails/*` such as Active Storage signed URLs, Action Mailbox, Mailers). |
|
|
55
56
|
| `exclude_paths` | `Array<String>` | `[]` | Array of path prefixes to bypass (e.g. `%w[/api /assets]`). |
|
|
56
57
|
| `exclude_hosts` | `Array<String \| Regexp \| Proc>` | `[]` | Array of hosts or patterns to bypass from host redirection. |
|
|
57
58
|
| `locale_param` | `String` | `"locale"` | GET parameter key for locale. |
|
|
@@ -95,6 +96,8 @@ config.middleware.use Rack::UrlCanonicalizer,
|
|
|
95
96
|
exclude_hosts: %w[api.example.com]
|
|
96
97
|
```
|
|
97
98
|
|
|
99
|
+
> **Note:** Rails internal routes (`/rails/*`, such as Active Storage case-sensitive signed token URLs, Action Mailbox, and Mailer previews) are automatically protected from `downcase_path` by default (`downcase_exclude_rails_paths: true`). Setting custom `downcase_exclude_paths` will complement this default rather than overwrite it.
|
|
100
|
+
|
|
98
101
|
### Sinatra / Plain Rack
|
|
99
102
|
|
|
100
103
|
In `config.ru`:
|
|
@@ -8,6 +8,7 @@ module Rack
|
|
|
8
8
|
:downcase_path,
|
|
9
9
|
:downcase_paths,
|
|
10
10
|
:downcase_exclude_paths,
|
|
11
|
+
:downcase_exclude_rails_paths,
|
|
11
12
|
:exclude_paths,
|
|
12
13
|
:exclude_hosts,
|
|
13
14
|
:locale_param,
|
|
@@ -24,6 +25,7 @@ module Rack
|
|
|
24
25
|
@downcase_path = false
|
|
25
26
|
@downcase_paths = nil
|
|
26
27
|
@downcase_exclude_paths = []
|
|
28
|
+
@downcase_exclude_rails_paths = true
|
|
27
29
|
@exclude_paths = []
|
|
28
30
|
@exclude_hosts = []
|
|
29
31
|
@locale_param = 'locale'
|
|
@@ -8,6 +8,7 @@ require_relative 'url_canonicalizer/railtie'
|
|
|
8
8
|
module Rack
|
|
9
9
|
class UrlCanonicalizer
|
|
10
10
|
IPV4_REGEX = /\A\d{1,3}(?:\.\d{1,3}){3}\z/
|
|
11
|
+
DEFAULT_RAILS_PATH_PATTERN = %r{\A/+rails(/|\z)}i
|
|
11
12
|
REDIRECT_BODIES = {
|
|
12
13
|
301 => 'Moved Permanently',
|
|
13
14
|
302 => 'Found',
|
|
@@ -135,6 +136,7 @@ module Rack
|
|
|
135
136
|
end
|
|
136
137
|
|
|
137
138
|
def downcase_excluded?(path)
|
|
139
|
+
return true if @config.downcase_exclude_rails_paths && DEFAULT_RAILS_PATH_PATTERN.match?(path)
|
|
138
140
|
return false if @config.downcase_exclude_paths.nil? || @config.downcase_exclude_paths.empty?
|
|
139
141
|
|
|
140
142
|
match_path_patterns?(@config.downcase_exclude_paths, path)
|