-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
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
Further reduce usages of StringUtils
#9044
Conversation
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.
I briefly reviewed this PR, I'm not sure if all replacements are equivalent. At least the StringUtils.defaultString
should be replaced by the suggestion - not sure that all imports still fit
Signed-off-by: Bob Du <[email protected]>
Signed-off-by: Bob Du <[email protected]>
Signed-off-by: Bob Du <[email protected]>
Signed-off-by: Bob Du <[email protected]>
Signed-off-by: Bob Du <[email protected]>
Signed-off-by: Bob Du <[email protected]>
Signed-off-by: Bob Du <[email protected]>
Signed-off-by: Bob Du <[email protected]>
Signed-off-by: Bob Du <[email protected]>
Signed-off-by: Bob Du <[email protected]>
Signed-off-by: Bob Du <[email protected]>
Signed-off-by: Bob Du <[email protected]>
f26ce3d
to
744f3db
Compare
if (o.endsWith(removeSuffix2)) { | ||
o = o.substring(0, o.length() - removeSuffix2.length()); | ||
} | ||
final String expectedOrigin = o; |
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.
The extra o
variable seems like an unnecessary layer of indirection for the reader. Why not just name it expectedOrigin
to begin with and remove this line.
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.
expectedOrigin
is a local variable used in lambda, it must be a final
or effectively final
.
Of course we can set o
as another name for readability, but I think it is not very necessary as a temporary variable.
Signed-off-by: Bob Du <[email protected]>
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.
Looks great! Many thanks for this contribution. Just two minor comments and I am ready to approve this PR.
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.
Many thanks for the PR!
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.
This PR is now ready for merge. We will merge it after approximately 24 hours if there is no negative feedback.
/label ready-for-merge
@@ -65,7 +64,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha | |||
HttpServletResponse rsp = (HttpServletResponse) response; | |||
String authorization = req.getHeader("Authorization"); | |||
|
|||
if (StringUtils.startsWithIgnoreCase(authorization, "Basic ")) { | |||
if (authorization != null && authorization.toLowerCase().startsWith("Basic ".toLowerCase())) { |
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.
While it is unlikely to matter in practice, this is not a sound replacement. If a request was sent with
AUTHORIZATION: BASIC czNjcjN0
then a server running in Turkish locale (e.g., #9066, though here it is the server not client locale which matters) would fail this clause because
"basıc cznjcjn0".startsWith("basic ")
is false.
In general, you always want to pass the Locale
argument (almost always Locale.ROOT
) to toLowerCase
/ toUpperCase
.
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.
@BobDu Is it worth filing a follow-up PR to address the above feedback? Or do we think the code is fine as-is?
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.
I agree always add Locale.ROOT
arg to toLowerCase
method is a best practices.
Already make a new PR #9162
like #6270
Testing done
Proposed changelog entries
Proposed upgrade guidelines
N/A
Submitter checklist
Desired reviewers
@mention
Before the changes are marked as
ready-for-merge
:Maintainer checklist