You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@trafficserver.apache.org by shenzhang920 <gi...@git.apache.org> on 2016/04/05 03:18:51 UTC

[GitHub] trafficserver pull request: TS-4312: Adding config to parse urls a...

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

    https://github.com/apache/trafficserver/pull/541#discussion_r58474731
  
    --- Diff: proxy/hdrs/URL.cc ---
    @@ -1158,9 +1158,51 @@ url_parse_scheme(HdrHeap *heap, URLImpl *url, const char **start, const char *en
       return PARSE_ERROR; // no non-whitespace found
     }
     
    +static bool
    +url_init_non_encoded_char_array(char *non_encoded_char, size_t size)
    +{
    +  const char *allowed_char = ":/?#[]@"                     // gen-delims
    +                              "!$&'()*+,;="                // sub-delims
    +                              "ABCDEFGHIJKLMNOPQRSTUVWXYZ" // ALPHA
    +                              "abcdefghijklmnopqrstuvwxyz"
    +                              "0123456789"                 // DIGIT
    +                              "-._~"                       // other unreserved
    +                              "%";                         // '%' should also not be encoded
    +
    +  memset(non_encoded_char, 0, size);
    +  for (size_t i = 0; i < strlen(allowed_char); ++i) {
    +    ink_assert((unsigned char)allowed_char[i] < size);
    +    non_encoded_char[(unsigned char)allowed_char[i]] = 1;
    +  }
    +
    +  return true;
    +}
    +
    +static char non_encoded_char[256];
    +static bool url_init_non_encoded_char_array_done = url_init_non_encoded_char_array(non_encoded_char, sizeof(non_encoded_char));
    --- End diff --
    
    Hardcoding would look like as below, it is error prone.  Should I change it?
    
    static const char non_encoded_char[256] = {
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // ! # $ % & ' ( ) * + , - . /
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, // 0-9 : ; = ?
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // @ A-O
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, // P-Z [ ] _
        0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // a-o
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0  // p-z ~
        // values of indices from 128 to 255 are all 0
      };



---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---