Skip to content

Commit a1e62ed

Browse files
authored
Merge pull request #2638 from ruby-grape/remove_path_dup
Remove unnecessary path string duplication
2 parents 927d55a + b1c38a7 commit a1e62ed

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* [#2629](https://github.com/ruby-grape/grape/pull/2629): Refactor Router Architecture - [@ericproulx](https://github.com/ericproulx).
66
* [#2633](https://github.com/ruby-grape/grape/pull/2633): Refactor API::Instance and reorganize DSL modules - [@ericproulx](https://github.com/ericproulx).
77
* [#2636](https://github.com/ruby-grape/grape/pull/2636): Refactor router to simplify method signatures and reduce duplication - [@ericproulx](https://github.com/ericproulx).
8+
* [#2638](https://github.com/ruby-grape/grape/pull/2638): Remove unnecessary path string duplication - [@ericproulx](https://github.com/ericproulx).
89
* Your contribution here.
910

1011
#### Fixes

lib/grape/middleware/versioner/path.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def before
2222
return if path_info == '/'
2323

2424
[mount_path, Grape::Router.normalize_path(prefix)].each do |path|
25-
path_info.delete_prefix!(path) if path.present? && path != '/' && path_info.start_with?(path)
25+
path_info = path_info.delete_prefix(path) if path.present? && path != '/' && path_info.start_with?(path)
2626
end
2727

2828
slash_position = path_info.index('/', 1) # omit the first one

lib/grape/router.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def self.normalize_path(path)
1616
return path if path == '/'
1717

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

2121
# Slow path
2222
encoding = path.encoding

0 commit comments

Comments
 (0)