This is an automated email from the ASF dual-hosted git repository.
cmcfarlen pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/10.1.x by this push:
new 2eba109b0a HRW: Support \r, \n and \t as ctrl chars in values (#12528)
(#12547)
2eba109b0a is described below
commit 2eba109b0a4a3e26567074dfd51b9da844a47bc0
Author: Chris McFarlen <[email protected]>
AuthorDate: Tue Oct 7 13:37:46 2025 -0400
HRW: Support \r, \n and \t as ctrl chars in values (#12528) (#12547)
(cherry picked from commit 9d3f93405832f74d6dd6f73a59c9add52ae4774f)
Co-authored-by: Leif Hedstrom <[email protected]>
---
plugins/header_rewrite/parser.cc | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/plugins/header_rewrite/parser.cc b/plugins/header_rewrite/parser.cc
index 921ec2f83a..7fbe381684 100644
--- a/plugins/header_rewrite/parser.cc
+++ b/plugins/header_rewrite/parser.cc
@@ -23,6 +23,7 @@
#include <iostream>
#include <string>
#include <sstream>
+#include <string_view>
#include "ts/ts.h"
@@ -65,12 +66,25 @@ Parser::parse_line(const std::string &original_line)
extracting_token = false;
}
} else if ((state != PARSER_IN_REGEX) && (line[i] == '\\')) {
- // Escaping
+ // Escaping - convert escape sequences to control characters
if (!extracting_token) {
extracting_token = true;
cur_token_start = i;
}
- line.erase(i, 1);
+ // Check if next character forms an escape sequence we want to convert
+ if (i + 1 < line.size()) {
+ constexpr std::string_view controls{"trn", 3};
+ constexpr char mapped_ctrls[] = "\t\r\n";
+
+ if (auto pos = controls.find(line[i + 1]); pos !=
std::string_view::npos) {
+ line[i] = mapped_ctrls[pos];
+ line.erase(i + 1, 1);
+ } else {
+ line.erase(i, 1);
+ }
+ } else {
+ line.erase(i, 1); // Backslash at end of line
+ }
} else if ((state != PARSER_IN_REGEX) && (line[i] == '"')) {
if ((state != PARSER_IN_QUOTE) && !extracting_token) {
state = PARSER_IN_QUOTE;