Skip to content
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

Merged
merged 1 commit into from
Sep 8, 2016

Conversation

masaori335
Copy link
Contributor

@masaori335 masaori335 commented Sep 1, 2016

@masaori335 masaori335 changed the title Allow backslash-escape in header_rewrite rules TS-4797: Allow backslash-escape in header_rewrite rules Sep 1, 2016
@masaori335 masaori335 added this to the 7.0.0 milestone Sep 1, 2016
@atsci
Copy link

atsci commented Sep 1, 2016

FreeBSD build successful! See https://ci.trafficserver.apache.org/job/Github-FreeBSD/660/ for details.

@atsci
Copy link

atsci commented Sep 1, 2016

Linux build successful! See https://ci.trafficserver.apache.org/job/Github-Linux/555/ for details.

@zwoop
Copy link
Contributor

zwoop commented Sep 1, 2016

👍

@@ -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) {
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Member

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.

@zwoop zwoop self-assigned this Sep 2, 2016
@maskit
Copy link
Member

maskit commented Sep 3, 2016

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".

@atsci
Copy link

atsci commented Sep 5, 2016

FreeBSD build successful! See https://ci.trafficserver.apache.org/job/Github-FreeBSD/696/ for details.

@atsci
Copy link

atsci commented Sep 5, 2016

Linux build successful! See https://ci.trafficserver.apache.org/job/Github-Linux/592/ for details.

@masaori335
Copy link
Contributor Author

Please take another look.
I added test cases which @maskit pointed out. And allow backslash-escape outside of quoted-string too.

@atsci
Copy link

atsci commented Sep 5, 2016

Linux build successful! See https://ci.trafficserver.apache.org/job/Github-Linux/593/ for details.

@atsci
Copy link

atsci commented Sep 5, 2016

FreeBSD build successful! See https://ci.trafficserver.apache.org/job/Github-FreeBSD/697/ for details.

@maskit
Copy link
Member

maskit commented Sep 7, 2016

👍

@masaori335 masaori335 merged commit 698f572 into apache:master Sep 8, 2016
JosiahWI pushed a commit to JosiahWI/trafficserver that referenced this pull request Jul 8, 2024
* Normalize Accept-Encoding header value before cache lookup

Co-authored-by: Min Chen <mchen@yahoo-corp.jp>
(cherry picked from commit 6363c94)

Conflicts:
      proxy/http/HttpSM.cc

* Remove select_ports

(cherry picked from commit fa57f1d)

---------

Co-authored-by: Masakazu Kitajo <maskit@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants