Skip to content
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

utility: remove absl::strings_internal::memcasecmp usage (#2700) #2702

Merged
merged 2 commits into from
Mar 5, 2018

Conversation

athampy
Copy link
Member

@athampy athampy commented Mar 2, 2018

title: Remove absl::strings_internal usage in utility

Description:
Replace use of absl::strings_internal::memcasecmp() in utility with absl::StartsWithIgnoreCase. This removes dependency on Abseil's internals and is inline with the Abseil Compatibility Guidelines..

Risk Level: Low

Testing: Ran unit tests
bazel test //test/common/common:utility_test

Linux version 4.4.0-116-generic (buildd@lgw01-amd64-021) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.9) )

Docs Changes:N/A

Release Notes: N/A

Fixes #2700

…2700)

Signed-off-by: Akhil Thampy <akhilthampy@yahoo.com>
@ggreenway
Copy link
Contributor

Some tests are failing with the change. At a quick glance the change looks correct; is there a subtle behavior difference here?

@@ -134,7 +134,7 @@ bool StringUtil::caseCompare(absl::string_view lhs, absl::string_view rhs) {
if (rhs.size() != lhs.size()) {
return false;
}
return absl::strings_internal::memcasecmp(rhs.data(), lhs.data(), rhs.size()) == 0;
return absl::StartsWithIgnoreCase(rhs.data(), lhs.data());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try swapping lhs and rhs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jmarantz gzip_filter_test passed after removing .data() calls
https://gist.github.com/athampy/545550bbd2b1bcb461cb9d677ef802f2

Copy link
Contributor

@srikailash srikailash Mar 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right! @athampy absl::StartsWithIgnoreCase expects absl::string_view while var.data() returns a char *
https://github.com/abseil/abseil-cpp/blob/master/absl/strings/match.cc#L30

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly!

Here's what I think is happening:

absl::string_view.size() doesn't necessarily represent the size of the underlying char*
When we pass in rhs.data(), for example, it gets implicitly converted to an absl::string_view where the size() == size of the char*

This becomes a problem when we have:

lhs = <absl::string_view> (_ptr="my;test;string", size=3)
// lhs.data() is "my;test;string" which gets converted to absl::string_view with size=14

rhs = <absl::string_view> (_ptr="my;", size=3)
// rhs.data() is "my;" which gets converted to absl::string_view with size=3

absl::StartsWithIgnoreCase(rhs.data(), lhs.data()) -> false // rhs.size() is not >= lhs.size()

…ing_view.data() (envoyproxy#2700)

Signed-off-by: Akhil Thampy <akhilthampy@yahoo.com>
@alyssawilk alyssawilk merged commit faadda1 into envoyproxy:master Mar 5, 2018
lita pushed a commit to lita/envoy that referenced this pull request Mar 5, 2018
jpsim pushed a commit that referenced this pull request Nov 28, 2022
This fixes up issues exposed in #24151 where the PlatformBridgeCertValidatorFactory was not associated with the PlatformBridgeCertValidator proto.

Risk Level: low
Testing: #24151
Docs Changes: n/a
Release Notes: n/a

Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
Signed-off-by: JP Simard <jp@jpsim.com>
jpsim pushed a commit that referenced this pull request Nov 29, 2022
This fixes up issues exposed in #24151 where the PlatformBridgeCertValidatorFactory was not associated with the PlatformBridgeCertValidator proto.

Risk Level: low
Testing: #24151
Docs Changes: n/a
Release Notes: n/a

Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
Signed-off-by: JP Simard <jp@jpsim.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants