pike.git
/
src
/
modules
/
_Roxen
/
roxen.c
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/src/modules/_Roxen/roxen.c:370:
*(pnt++) = '\n'; } pop_n_elems( args ); push_string( end_shared_string( res ) ); } 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
prior
-
*!
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.
+
*!
*! @note *! Performs a best-effort decoding. Invalid and truncated escapes *! will still be decoded. */ { int proc = 0; int trunc = 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:
p_wchar2 hex = INDEX_PCHARP(foo, 2); c = (((hex<'A')?hex:(hex + 9)) & 15)<<12; hex = INDEX_PCHARP(foo, 3); c |= (((hex<'A')?hex:(hex + 9)) & 15)<<8; hex = INDEX_PCHARP(foo, 4); c |= (((hex<'A')?hex:(hex + 9)) & 15)<<4; hex = INDEX_PCHARP(foo, 5); c |= ((hex<'A')?hex:(hex + 9)) & 15; } INC_PCHARP(foo, 5);
+
if ((c & 0xf800) == 0xd800) {
+
got_surrogates = 1;
+
}
} else { c = 0; if (SUBTRACT_PCHARP(end, foo) > 2) { p_wchar2 hex = INDEX_PCHARP(foo, 1); c = (((hex<'A')?hex:(hex + 9)) & 15)<<4; hex = INDEX_PCHARP(foo, 2); c |= ((hex<'A')?hex:(hex + 9)) & 15; } 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;