Skip to content

Commit ea45bc1

Browse files
authored
Merge pull request #2582 from ericproulx/fix_leaky_slash
Fix leaky slash when normalizing
2 parents 2dd0bd9 + 7b330f9 commit ea45bc1

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
* [#2573](https://github.com/ruby-grape/grape/pull/2573): Clean up deprecated code - [@ericproulx](https://github.com/ericproulx).
77
* [#2575](https://github.com/ruby-grape/grape/pull/2575): Refactor Api description class - [@ericproulx](https://github.com/ericproulx).
88
* [#2577](https://github.com/ruby-grape/grape/pull/2577): Deprecate `return` in endpoint execution - [@ericproulx](https://github.com/ericproulx).
9-
* [#13](https://github.com/ericproulx/grape/pull/13): Refactor endpoint helpers and error middleware integration - [@ericproulx](https://github.com/ericproulx).
9+
* [#2580](https://github.com/ruby-grape/grape/pull/2580): Refactor endpoint helpers and error middleware integration - [@ericproulx](https://github.com/ericproulx).
10+
* [#2582](https://github.com/ruby-grape/grape/pull/2582): Fix leaky slash when normalizing - [@ericproulx](https://github.com/ericproulx).
1011
* Your contribution here.
1112

1213
#### Fixes

lib/grape/router.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ class Router
1212
# normalize_path("/%ab") # => "/%AB"
1313
# https://github.com/rails/rails/blob/00cc4ff0259c0185fe08baadaa40e63ea2534f6e/actionpack/lib/action_dispatch/journey/router/utils.rb#L19
1414
def self.normalize_path(path)
15-
return +'/' unless path
15+
return '/' unless path
16+
return path if path == '/'
1617

1718
# Fast path for the overwhelming majority of paths that don't need to be normalized
18-
return path.dup if path == '/' || (path.start_with?('/') && !(path.end_with?('/') || path.match?(%r{%|//})))
19+
return path.dup if path.start_with?('/') && !(path.end_with?('/') || path.match?(%r{%|//}))
1920

2021
# Slow path
2122
encoding = path.encoding

0 commit comments

Comments
 (0)