This is an automated email from the ASF dual-hosted git repository.
zwoop pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 9d3f934058 HRW: Support \r, \n and \t as ctrl chars in values (#12528)
9d3f934058 is described below
commit 9d3f93405832f74d6dd6f73a59c9add52ae4774f
Author: Leif Hedstrom <[email protected]>
AuthorDate: Wed Oct 1 16:19:21 2025 -0600
HRW: Support \r, \n and \t as ctrl chars in values (#12528)
---
plugins/header_rewrite/parser.cc | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/plugins/header_rewrite/parser.cc b/plugins/header_rewrite/parser.cc
index 006d700680..970da3a725 100644
--- a/plugins/header_rewrite/parser.cc
+++ b/plugins/header_rewrite/parser.cc
@@ -24,6 +24,7 @@
#include <fstream>
#include <sstream>
#include <filesystem>
+#include <string_view>
#include "ts/ts.h"
#include "tscore/Layout.h"
@@ -67,12 +68,26 @@ 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) && (state != PARSER_IN_PAREN) &&
(line[i] == '"')) {
if ((state != PARSER_IN_QUOTE) && !extracting_token) {
state = PARSER_IN_QUOTE;