Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions STYLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
annotations](https://github.com/abseil/abseil-cpp/blob/master/absl/base/thread_annotations.h),
such as `GUARDED_BY`, should be used for shared state guarded by
locks/mutexes.
* Functions intended to be local to a cc file should be declared in an anonymonus namespace,
rather than using the 'static' keyword. Note that the
[Google C++ style guide](https://google.github.io/styleguide/cppguide.html#Unnamed_Namespaces_and_Static_Variables)
allows either, but in Envoy we prefer annonymous namespaces.

# Error handling

Expand Down
6 changes: 5 additions & 1 deletion source/common/stats/stats_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ size_t roundUpMultipleNaturalAlignment(size_t val) {
return (val + multiple - 1) & ~(multiple - 1);
}

bool regexStartsWithDot(absl::string_view regex) {
return absl::StartsWith(regex, "\\.") || absl::StartsWith(regex, "(?=\\.)");
}

} // namespace

size_t RawStatData::size() {
Expand Down Expand Up @@ -75,7 +79,7 @@ std::string TagExtractorImpl::extractRegexPrefix(absl::string_view regex) {
if (!absl::ascii_isalnum(regex[i]) && (regex[i] != '_')) {
if (i > 1) {
const bool last_char = i == regex.size() - 1;
if ((!last_char && (regex[i] == '\\') && (regex[i + 1] == '.')) ||
if ((!last_char && regexStartsWithDot(regex.substr(i))) ||
(last_char && (regex[i] == '$'))) {
prefix.append(regex.data() + 1, i - 1);
}
Expand Down
1 change: 1 addition & 0 deletions test/common/stats/stats_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ TEST(TagExtractorTest, ExtractRegexPrefix) {

EXPECT_EQ("", extractRegexPrefix("^prefix(foo)."));
EXPECT_EQ("prefix", extractRegexPrefix("^prefix\\.foo"));
EXPECT_EQ("prefix_optional", extractRegexPrefix("^prefix_optional(?=\\.)"));
EXPECT_EQ("", extractRegexPrefix("^notACompleteToken")); //
EXPECT_EQ("onlyToken", extractRegexPrefix("^onlyToken$")); //
EXPECT_EQ("", extractRegexPrefix("(prefix)"));
Expand Down