Github user maskit commented on a diff in the pull request:

    https://github.com/apache/trafficserver/pull/951#discussion_r77433626
  
    --- Diff: plugins/header_rewrite/parser.cc ---
    @@ -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) {
    --- End diff --
    
    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.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to