Skip to content

Commit

Permalink
dep: Update RE2 to 2023-07-01
Browse files Browse the repository at this point in the history
Signed-off-by: Yan Avlasov <yavlasov@google.com>
  • Loading branch information
yanavlasov committed Jul 26, 2023
1 parent afaf00b commit 321cfc4
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 25 deletions.
6 changes: 3 additions & 3 deletions bazel/repository_locations.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1200,12 +1200,12 @@ REPOSITORY_LOCATIONS_SPEC = dict(
project_name = "RE2",
project_desc = "RE2, a regular expression library",
project_url = "https://github.com/google/re2",
version = "2023-03-01",
sha256 = "7a9a4824958586980926a300b4717202485c4b4115ac031822e29aa4ef207e48",
version = "2023-07-01",
sha256 = "18cf85922e27fad3ed9c96a27733037da445f35eb1a2744c306a37c6d11e95c4",
strip_prefix = "re2-{version}",
urls = ["https://github.com/google/re2/archive/{version}.tar.gz"],
use_category = ["controlplane", "dataplane_core"],
release_date = "2023-03-01",
release_date = "2023-07-01",
cpe = "N/A",
license = "BSD-3-Clause",
license_url = "https://github.com/google/re2/blob/{version}/LICENSE",
Expand Down
20 changes: 10 additions & 10 deletions source/common/router/header_parser_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ std::string HeaderParser::translateMetadataFormat(const std::string& header_valu
const re2::RE2& re = getMetadataTranslatorPattern();
ASSERT(re.ok());
std::string new_header_value = header_value;
re2::StringPiece matches[3];
absl::string_view matches[3];
while (re.Match(new_header_value, 0, new_header_value.size(), re2::RE2::UNANCHORED, matches, 3)) {
TRY_ASSERT_MAIN_THREAD {
std::string new_format;
Expand All @@ -42,13 +42,13 @@ std::string HeaderParser::translateMetadataFormat(const std::string& header_valu
new_format += ":" + parsed_params->asObjectArray()[i]->asString();
}

new_format = "%" + matches[1].as_string() + "_METADATA(" + new_format + ")%";
ENVOY_LOG_MISC(
warn,
"Header formatter: JSON format of {} parameters has been obsoleted. Use colon format: {}",
matches[1].as_string() + "_METADATA", new_format.c_str());
new_format = absl::StrCat("%", matches[1], "_METADATA(", new_format, ")%");
ENVOY_LOG_MISC(warn,
"Header formatter: JSON format of {}_METADATA parameters has been obsoleted. "
"Use colon format: {}",
matches[1], new_format.c_str());

int subs = absl::StrReplaceAll({{matches[0].as_string(), new_format}}, &new_header_value);
int subs = absl::StrReplaceAll({{matches[0], new_format}}, &new_header_value);
ASSERT(subs > 0);
}
END_TRY CATCH(Json::Exception & e, { return header_value; });
Expand All @@ -71,13 +71,13 @@ std::string HeaderParser::translatePerRequestState(const std::string& header_val
const re2::RE2& re = getPerRequestTranslatorPattern();
ASSERT(re.ok());
std::string new_header_value = header_value;
re2::StringPiece matches[2];
absl::string_view matches[2];
while (re.Match(new_header_value, 0, new_header_value.size(), re2::RE2::UNANCHORED, matches, 2)) {
const std::string new_format = "%FILTER_STATE(" + matches[1].as_string() + ":PLAIN)%";
const std::string new_format = absl::StrCat("%FILTER_STATE(", matches[1], ":PLAIN)%");

ENVOY_LOG_MISC(warn, "PER_REQUEST_STATE header formatter has been obsoleted. Use {}",
new_format.c_str());
int subs = absl::StrReplaceAll({{matches[0].as_string(), new_format}}, &new_header_value);
int subs = absl::StrReplaceAll({{matches[0], new_format}}, &new_header_value);
ASSERT(subs > 0);
}
return new_header_value;
Expand Down
5 changes: 2 additions & 3 deletions source/common/stats/tag_extractor_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,10 @@ bool TagExtractorRe2Impl::extractTag(TagExtractionContext& context, std::vector<
}

// remove_subexpr is the first submatch. It represents the portion of the string to be removed.
re2::StringPiece remove_subexpr, value_subexpr;
absl::string_view remove_subexpr, value_subexpr;

// The regex must match and contain one or more subexpressions (all after the first are ignored).
if (re2::RE2::PartialMatch(re2::StringPiece(stat_name.data(), stat_name.size()), regex_,
&remove_subexpr, &value_subexpr) &&
if (re2::RE2::PartialMatch(stat_name, regex_, &remove_subexpr, &value_subexpr) &&
!remove_subexpr.empty()) {

// value_subexpr is the optional second submatch. It is usually inside the first submatch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ absl::StatusOr<std::string> UriTemplateRewriter::rewritePath(absl::string_view p

// First capture is the whole matched regex pattern.
int capture_num = regex.NumberOfCapturingGroups() + 1;
std::vector<re2::StringPiece> captures(capture_num);
std::vector<absl::string_view> captures(capture_num);
if (!regex.Match(pattern, /*startpos=*/0,
/*endpos=*/pattern.size(), RE2::ANCHOR_BOTH, captures.data(), captures.size())) {
return absl::InvalidArgumentError("Pattern not match");
Expand All @@ -75,7 +75,7 @@ absl::StatusOr<std::string> UriTemplateRewriter::rewritePath(absl::string_view p
if (literal != nullptr) {
absl::StrAppend(&new_path, *literal);
} else if (capture_index != nullptr) {
absl::StrAppend(&new_path, absl::string_view(captures[*capture_index].as_string()));
absl::StrAppend(&new_path, captures[*capture_index]);
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/common/common/re_speed_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static void BM_RE2(benchmark::State& state) {
uint32_t passes = 0;
for (auto _ : state) { // NOLINT
for (const char* cluster_input : ClusterInputs) {
re2::StringPiece match1, match2;
absl::string_view match1, match2;
if (re2::RE2::PartialMatch(cluster_input, re, &match1, &match2)) {
ASSERT(match1 == "match.");
ASSERT(match2 == "match");
Expand All @@ -115,7 +115,7 @@ static void BM_RE2_AltPattern(benchmark::State& state) {
uint32_t passes = 0;
for (auto _ : state) { // NOLINT
for (const char* cluster_input : ClusterInputs) {
re2::StringPiece match1, match2;
absl::string_view match1, match2;
if (re2::RE2::PartialMatch(cluster_input, re, &match1, &match2)) {
ASSERT(match1 == "match.");
ASSERT(match2 == "match");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,13 @@ TEST(InternalRegexGen, LiteralMatches) {
}

TEST(InternalRegexGen, LiteralMatchesInNamedCapture) {
re2::StringPiece kPattern = "abcABC123/-._~%20!$&'()+,;:@";
absl::string_view kPattern = "abcABC123/-._~%20!$&'()+,;:@";

RE2 regex = RE2(absl::StrCat("(?P<var>", toRegexPattern(kPattern), ")"));
ASSERT_EQ(regex.NumberOfCapturingGroups(), 1);

// Full matched string + capture groups
std::vector<re2::StringPiece> captures(2);
std::vector<absl::string_view> captures(2);
ASSERT_TRUE(regex.Match(kPattern, /*startpos=*/0, /*endpos=*/kPattern.size(), RE2::ANCHOR_BOTH,
captures.data(), captures.size()));

Expand Down Expand Up @@ -332,15 +332,15 @@ TEST(InternalRegexGen, VariableRegexTextGlobMatch) {
}

TEST(InternalRegexGen, VariableRegexNamedCapture) {
re2::StringPiece kPattern = "abc";
absl::string_view kPattern = "abc";
absl::StatusOr<ParsedResult<Variable>> var = parseVariable("{var=*}");
ASSERT_OK(var);

RE2 regex = RE2(toRegexPattern(var->parsed_value_));
ASSERT_EQ(regex.NumberOfCapturingGroups(), 1);

// Full matched string + capture groups
std::vector<re2::StringPiece> captures(2);
std::vector<absl::string_view> captures(2);
ASSERT_TRUE(regex.Match(kPattern, /*startpos=*/0, /*endpos=*/kPattern.size(), RE2::ANCHOR_BOTH,
captures.data(), captures.size()));

Expand Down Expand Up @@ -429,7 +429,7 @@ TEST_P(GenPatternRegexWithMatch, WithCapture) {
ASSERT_EQ(regex.NumberOfCapturingGroups(), varValues().size());

int capture_num = regex.NumberOfCapturingGroups() + 1;
std::vector<re2::StringPiece> captures(capture_num);
std::vector<absl::string_view> captures(capture_num);
ASSERT_TRUE(regex.Match(requestPath(), /*startpos=*/0,
/*endpos=*/requestPath().size(), RE2::ANCHOR_BOTH, captures.data(),
captures.size()));
Expand Down

0 comments on commit 321cfc4

Please sign in to comment.