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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0cc0592b66830e51b4f791b9b7c9503fa98ca0c20f25fb4fe92ae9379af404ed
4
- data.tar.gz: 572708d83ec547c190e93d78dd900db96af8de7cca0c3760122a132fef8282c6
3
+ metadata.gz: 894b233627b42a6f6db8d6962f8622cd768b39603f1f569b79a45d413c89a95d
4
+ data.tar.gz: 1875213c68bdd7bb0cc6df9b84984117d98ef1d23a678c0c0268d3ee51690936
5
5
  SHA512:
6
- metadata.gz: 1e1b05c26326297a9b6cd425433face278ebeae8d9ca9deddf34f637d092b3f8875d64591cf5b59a0265187933cfcbe88822ef5c0d52a7c30f08b6010c19f0d8
7
- data.tar.gz: ffc8f3651b5a9bd64a50365dd86e9a5f9129903bfd4e998d44da3a3a8a024f30a60673bfd4e6aea365954cb12299985de08c95bf12df3e0daa04ad9c59c6989e
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'
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rack
4
4
  class UrlCanonicalizer
5
- VERSION = '0.3.0'
5
+ VERSION = '0.3.1'
6
6
  end
7
7
  end
@@ -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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-url-canonicalizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Abramov