serrislew commented on a change in pull request #8235:
URL: https://github.com/apache/trafficserver/pull/8235#discussion_r698660934
##########
File path: plugins/header_rewrite/value.h
##########
@@ -59,6 +59,26 @@ class Value : Statement
} else {
s += _value;
}
+ if (regex_vector.size() > 1) {
+ replace_regex_sub(s, regex_vector);
+ }
+ }
+
+ void
+ replace_regex_sub(std::string &s, std::vector<std::string> regex_vector)
const
+ {
+ int vector_size = static_cast<int>(regex_vector.size());
+ std::size_t sub = s.find("$");
+ while (sub != std::string::npos && sub < s.length() - 1) {
+ int sub_num = std::stoi(s.substr(sub + 1, 1));
+ if (sub_num > 0 && sub_num < vector_size) {
+ TSDebug(PLUGIN_NAME, "Replacing regex group $%d: %s", sub_num,
regex_vector[sub_num].c_str());
+ s.replace(sub, 2, regex_vector[sub_num]);
+ sub = s.find("$");
Review comment:
The string lookup checks for any single digit string with the format
'$n' so it will work for '$2' and any number between 1-9. It will either find
the next '$n' string or if there are no more, it will terminate with the
conditional `sub != std::string::npos`
and to reply to your above comment on `std::regex`, my latest commit should
include code no longer using `std::regex`. From Leif's suggestion, I have
upgraded my code to use pcre library instead, to also maintain compatibility
with the regex used
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]