SolidWallOfCode commented on a change in pull request #8235:
URL: https://github.com/apache/trafficserver/pull/8235#discussion_r698083326



##########
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:
       Why not start at `sub+1`? What if the replacement string has "$2" in it? 
Would you want to expand that also? Seems like there's a risk of an infinite 
loop.




-- 
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]


Reply via email to