pike.git / src / modules / _Roxen / roxen.c

version» Context lines:

pike.git/src/modules/_Roxen/roxen.c:370:   {    if(hex>='0' && hex<='9')    return hex-'0';    hex |= 32;    return hex-'W';   }      static void f_http_decode_string(INT32 args)   /*! @decl string http_decode_string(string encoded)    *! -  *! Decodes an http transport-encoded string. Knows about %XX and -  *! %uXXXX syntax. Treats %UXXXX as %uXXXX. It will treat '+' as '+' -  *! and not ' ', so form decoding needs to replace that in a second -  *! step. +  *! Decodes an http transport-encoded string. Knows about @tt{%XX@} and +  *! @tt{%uXXXX@} syntax. Treats @tt{%UXXXX@} as @tt{%uXXXX@}. It will +  *! treat '+' as '+' and not ' ', so form decoding needs to replace that +  *! in a second step. +  *! +  *! It also knows about UTF-16 surrogate pairs when decoding @tt{%UXXXX@} +  *! sequences.    */   {    int proc = 0;    int size_shift; -  +  int got_surrogates = 0;    PCHARP foo, end;    struct string_builder newstr;       if (!args || TYPEOF(Pike_sp[-args]) != PIKE_T_STRING)    Pike_error("Invalid argument to http_decode_string(string).\n");       foo = MKPCHARP_STR(Pike_sp[-args].u.string);    end = ADD_PCHARP(foo, Pike_sp[-args].u.string->len);       size_shift = Pike_sp[-args].u.string->size_shift;
pike.git/src/modules/_Roxen/roxen.c:450:    if (c == 'u' || c == 'U') {    p_wchar2 hex = INDEX_PCHARP(foo, 2);    c = parse_hexchar(hex)<<12;    hex = INDEX_PCHARP(foo, 3);    c |= parse_hexchar(hex)<<8;    hex = INDEX_PCHARP(foo, 4);    c |= parse_hexchar(hex)<<4;    hex = INDEX_PCHARP(foo, 5);    c |= parse_hexchar(hex);    INC_PCHARP(foo, 5); +  if ((c & 0xf800) == 0xd800) { +  got_surrogates = 1; +  }    } else {    p_wchar2 hex = INDEX_PCHARP(foo, 1);    c = parse_hexchar(hex)<<4;    hex = INDEX_PCHARP(foo, 2);    c |= parse_hexchar(hex);    INC_PCHARP(foo, 2);    }    }    string_builder_putchar(&newstr, c);    }       pop_n_elems(args); -  +  +  if (got_surrogates) { +  /* Convert the result string to a byte string. */ +  newstr.s->size_shift = 0; +  newstr.known_shift = 0; +  newstr.s->len <<= 1; +  +  /* Then run unicode_to_string() in native byte-order. */    push_string(finish_string_builder(&newstr)); -  +  push_int(2); +  f_unicode_to_string(2); +  } else { +  push_string(finish_string_builder(&newstr));    } -  + }      static void f_html_encode_string( INT32 args )   /*! @decl string html_encode_string(mixed in)    *!    *! Encodes the @[in] data as an HTML safe string.    */   {    struct pike_string *str;    int newlen;    INT32 min;