Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
8d69183b
Commit
8d69183b
authored
Jan 13, 2021
by
Robert May
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Relocate method to utils
parent
c99f7bd3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
15 deletions
+31
-15
app/helpers/application_helper.rb
app/helpers/application_helper.rb
+2
-15
lib/gitlab/utils.rb
lib/gitlab/utils.rb
+12
-0
spec/lib/gitlab/utils_spec.rb
spec/lib/gitlab/utils_spec.rb
+17
-0
No files found.
app/helpers/application_helper.rb
View file @
8d69183b
...
...
@@ -44,7 +44,7 @@ module ApplicationHelper
# current_controller?('gitlab/application') # => false
def
current_controller?
(
*
args
)
args
.
any?
do
|
v
|
safe_downcase!
(
v
.
to_s
)
==
controller
.
controller_name
||
safe_downcase!
(
v
.
to_s
)
==
controller
.
controller_path
Gitlab
::
Utils
.
safe_downcase!
(
v
.
to_s
)
==
controller
.
controller_name
||
Gitlab
::
Utils
.
safe_downcase!
(
v
.
to_s
)
==
controller
.
controller_path
end
end
...
...
@@ -59,7 +59,7 @@ module ApplicationHelper
# current_action?(:create) # => false
# current_action?(:new, :create) # => true
def
current_action?
(
*
args
)
args
.
any?
{
|
v
|
safe_downcase!
(
v
.
to_s
)
==
action_name
}
args
.
any?
{
|
v
|
Gitlab
::
Utils
.
safe_downcase!
(
v
.
to_s
)
==
action_name
}
end
def
admin_section?
...
...
@@ -397,19 +397,6 @@ module ApplicationHelper
end
end
# A safe alternative to String#downcase!
#
# This will make copies of frozen strings but downcase unfrozen
# strings in place, reducing allocations.
def
safe_downcase!
(
str
)
if
str
.
frozen?
str
.
downcase
else
str
.
downcase!
||
str
end
end
private
def
appearance
...
...
lib/gitlab/utils.rb
View file @
8d69183b
...
...
@@ -174,6 +174,18 @@ module Gitlab
rescue
IPAddr
::
InvalidAddressError
end
# A safe alternative to String#downcase!
#
# This will make copies of frozen strings but downcase unfrozen
# strings in place, reducing allocations.
def
safe_downcase!
(
str
)
if
str
.
frozen?
str
.
downcase
else
str
.
downcase!
||
str
end
end
# Converts a string to an Addressable::URI object.
# If the string is not a valid URI, it returns nil.
# Param uri_string should be a String object.
...
...
spec/lib/gitlab/utils_spec.rb
View file @
8d69183b
...
...
@@ -392,6 +392,23 @@ RSpec.describe Gitlab::Utils do
end
end
describe
".safe_downcase!"
do
using
RSpec
::
Parameterized
::
TableSyntax
where
(
:str
,
:result
)
do
"test"
.
freeze
|
"test"
"Test"
.
freeze
|
"test"
"test"
|
"test"
"Test"
|
"test"
end
with_them
do
it
"downcases the string"
do
expect
(
described_class
.
safe_downcase!
(
str
)).
to
eq
(
result
)
end
end
end
describe
'.parse_url'
do
it
'returns Addressable::URI object'
do
expect
(
described_class
.
parse_url
(
'http://gitlab.com'
)).
to
be_instance_of
(
Addressable
::
URI
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment