-
Notifications
You must be signed in to change notification settings - Fork 268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check if calling force_encoding is necessary before doing so in Addressable::URI, replace with encode! where applicable #340
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -552,7 +552,7 @@ def self.normalize_component(component, character_class= | |
rescue ArgumentError | ||
encoded = self.encode_component(unencoded) | ||
end | ||
encoded.force_encoding(Encoding::UTF_8) | ||
encoded.encode!(Encoding::UTF_8, invalid: :replace, replace: "") | ||
return encoded | ||
end | ||
|
||
|
@@ -865,7 +865,9 @@ def normalized_scheme | |
end | ||
end | ||
# All normalized values should be UTF-8 | ||
@normalized_scheme.force_encoding(Encoding::UTF_8) if @normalized_scheme | ||
if @normalized_scheme && @normalized_scheme.encoding != Encoding::UTF_8 | ||
@normalized_scheme.encode!(Encoding::UTF_8, invalid: :replace, replace: "") | ||
end | ||
@normalized_scheme | ||
end | ||
|
||
|
@@ -920,7 +922,9 @@ def normalized_user | |
end | ||
end | ||
# All normalized values should be UTF-8 | ||
@normalized_user.force_encoding(Encoding::UTF_8) if @normalized_user | ||
if @normalized_user && @normalized_user.encoding != Encoding::UTF_8 | ||
@normalized_user.encode!(Encoding::UTF_8, invalid: :replace, replace: "") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/LineLength: Line is too long. [81/80] |
||
end | ||
@normalized_user | ||
end | ||
|
||
|
@@ -977,8 +981,8 @@ def normalized_password | |
end | ||
end | ||
# All normalized values should be UTF-8 | ||
if @normalized_password | ||
@normalized_password.force_encoding(Encoding::UTF_8) | ||
if @normalized_password && @normalized_password.encoding != Encoding::UTF_8 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/LineLength: Line is too long. [81/80] |
||
@normalized_password.encode!(Encoding::UTF_8, invalid: :replace, replace: "") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/LineLength: Line is too long. [85/80] |
||
end | ||
@normalized_password | ||
end | ||
|
@@ -1047,8 +1051,8 @@ def normalized_userinfo | |
end | ||
end | ||
# All normalized values should be UTF-8 | ||
if @normalized_userinfo | ||
@normalized_userinfo.force_encoding(Encoding::UTF_8) | ||
if @normalized_userinfo && @normalized_userinfo.encoding != Encoding::UTF_8 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/LineLength: Line is too long. [81/80] |
||
@normalized_userinfo.encode!(Encoding::UTF_8, invalid: :replace, replace: "") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/LineLength: Line is too long. [85/80] |
||
end | ||
@normalized_userinfo | ||
end | ||
|
@@ -1114,7 +1118,9 @@ def normalized_host | |
end | ||
end | ||
# All normalized values should be UTF-8 | ||
@normalized_host.force_encoding(Encoding::UTF_8) if @normalized_host | ||
if @normalized_host && @normalized_host.encoding != Encoding::UTF_8 | ||
@normalized_host.encode!(Encoding::UTF_8, invalid: :replace, replace: "") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/LineLength: Line is too long. [81/80] |
||
end | ||
@normalized_host | ||
end | ||
|
||
|
@@ -1232,8 +1238,8 @@ def normalized_authority | |
authority | ||
end | ||
# All normalized values should be UTF-8 | ||
if @normalized_authority | ||
@normalized_authority.force_encoding(Encoding::UTF_8) | ||
if @normalized_authority && @normalized_authority.encoding != Encoding::UTF_8 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/LineLength: Line is too long. [83/80] |
||
@normalized_authority.encode!(Encoding::UTF_8, invalid: :replace, replace: "") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/LineLength: Line is too long. [86/80] |
||
end | ||
@normalized_authority | ||
end | ||
|
@@ -1468,7 +1474,9 @@ def normalized_site | |
site_string | ||
end | ||
# All normalized values should be UTF-8 | ||
@normalized_site.force_encoding(Encoding::UTF_8) if @normalized_site | ||
if @normalized_site && @normalized_site.encoding != Encoding::UTF_8 | ||
@normalized_site.encode!(Encoding::UTF_8, invalid: :replace, replace: "") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/LineLength: Line is too long. [81/80] |
||
end | ||
@normalized_site | ||
end | ||
|
||
|
@@ -1531,7 +1539,9 @@ def normalized_path | |
result | ||
end | ||
# All normalized values should be UTF-8 | ||
@normalized_path.force_encoding(Encoding::UTF_8) if @normalized_path | ||
if @normalized_path && @normalized_path.encoding != Encoding::UTF_8 | ||
@normalized_path.encode!(Encoding::UTF_8, invalid: :replace, replace: "") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Layout/IndentationWidth: Use 2 (not 3) spaces for indentation. |
||
end | ||
@normalized_path | ||
end | ||
|
||
|
@@ -1602,7 +1612,9 @@ def normalized_query(*flags) | |
component == "" ? nil : component | ||
end | ||
# All normalized values should be UTF-8 | ||
@normalized_query.force_encoding(Encoding::UTF_8) if @normalized_query | ||
if @normalized_query && @normalized_query.encoding != Encoding::UTF_8 | ||
@normalized_query.encode!(Encoding::UTF_8, invalid: :replace, replace: "") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/LineLength: Line is too long. [82/80] |
||
end | ||
@normalized_query | ||
end | ||
|
||
|
@@ -1796,8 +1808,8 @@ def normalized_fragment | |
component == "" ? nil : component | ||
end | ||
# All normalized values should be UTF-8 | ||
if @normalized_fragment | ||
@normalized_fragment.force_encoding(Encoding::UTF_8) | ||
if @normalized_fragment && @normalized_fragment.encoding != Encoding::UTF_8 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/LineLength: Line is too long. [81/80] |
||
@normalized_fragment.encode!(Encoding::UTF_8, invalid: :replace, replace: "") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/LineLength: Line is too long. [85/80] |
||
end | ||
@normalized_fragment | ||
end | ||
|
@@ -2325,7 +2337,7 @@ def to_s | |
uri_string << self.path.to_s | ||
uri_string << "?#{self.query}" if self.query != nil | ||
uri_string << "##{self.fragment}" if self.fragment != nil | ||
uri_string.force_encoding(Encoding::UTF_8) | ||
uri_string.encode!(Encoding::UTF_8, invalid: :replace, replace: "") | ||
uri_string | ||
end | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [83/80]