-
Notifications
You must be signed in to change notification settings - Fork 797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TS-4797: Allow backslash-escape in header_rewrite rules #951
Conversation
masaori335
commented
Sep 1, 2016
•
edited
Loading
edited
- TS-4797
FreeBSD build successful! See https://ci.trafficserver.apache.org/job/Github-FreeBSD/660/ for details. |
Linux build successful! See https://ci.trafficserver.apache.org/job/Github-Linux/555/ for details. |
👍 |
@@ -50,6 +52,12 @@ Parser::Parser(const std::string &line) : _cond(false), _empty(false) | |||
_tokens.push_back(std::string(1, line[i])); | |||
} | |||
continue; /* always eat whitespace */ | |||
} else if (line[i] == '\\') { | |||
// erase a backslash in quoted-string | |||
if (inquote && extracting_token) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the inquote
condition? Why can't backquotes work outside of a quoted string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My commit message might be not suitable. What I want to fix is we can't use double quote inside of quoted string.
We can make this more general, but it makes header_rewrite rules and parser code more complicated.
Do you have any specific use cases to escape something outside of quoted string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this change, the test below passes.
{
ParserTest p("add-header foo \\var\\");
CHECK_EQ(p.getTokens().size(), 3);
CHECK_EQ(p.getTokens()[0], "add-header");
CHECK_EQ(p.getTokens()[1], "foo");
CHECK_EQ(p.getTokens()[2], "\\var\\");
}
But with this change, it fails.
The test case will need to be changed like:
CHECK_EQ(p.getTokens()[2], "var\\");
This seems very odd. Even if there is no actual use case, it's hard to understand the behavior.
However, it seems we don't support backslash-escaping completely outside of a quoted string string now, actually.
// This doesn't work but it's OK, maybe.
{
ParserTest p("add-header foo <bar>");
CHECK_EQ(p.getTokens().size(), 3);
}
// This doesn't work even without Masaori's change. I guess this is the case James pointed out.
{
ParserTest p("add-header foo \\<bar\\>");
CHECK_EQ(p.getTokens().size(), 3);
}
// This works either way.
{
ParserTest p("add-header foo \"<bar>\"");
CHECK_EQ(p.getTokens().size(), 3);
CHECK_EQ(p.getTokens()[0], "add-header");
CHECK_EQ(p.getTokens()[1], "foo");
CHECK_EQ(p.getTokens()[2], "<bar>");
}
I don't know whether this is a regression.
Anyway, more conservative codes would be:
if (!extracting_token) {
extracting_token = true;
cur_token_start = i;
}
if (inquote) {
line.erase(i, 1);
continue;
}
I think we should add all test cases above to clarify the cases now we support.
As I commented inline, this introduces an unexpected behavior. I suggest using the conservative change I wrote on the comment. Also, it's a trivial thing but I'd suggest using "bar" instead of "var". |
FreeBSD build successful! See https://ci.trafficserver.apache.org/job/Github-FreeBSD/696/ for details. |
Linux build successful! See https://ci.trafficserver.apache.org/job/Github-Linux/592/ for details. |
Please take another look. |
Linux build successful! See https://ci.trafficserver.apache.org/job/Github-Linux/593/ for details. |
FreeBSD build successful! See https://ci.trafficserver.apache.org/job/Github-FreeBSD/697/ for details. |
👍 |