joes 2003/02/27 13:30:10
Modified: . Changes
c apache_request.c
t cookie.t request-param.pl request.t
Log:
Applied Tatsuhiko Miyagawa's %uXXXX patch. Also mucking around with tests.
Revision Changes Path
1.47 +4 -0 httpd-apreq/Changes
Index: Changes
===================================================================
RCS file: /home/cvs/httpd-apreq/Changes,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -r1.46 -r1.47
--- Changes 27 Feb 2003 20:03:58 -0000 1.46
+++ Changes 27 Feb 2003 21:30:10 -0000 1.47
@@ -2,6 +2,10 @@
=over 4
+=item 1.12 - February 27, 2003
+
+Applied Tatsuhiko Miyagawa's patch for handling %uXXXX strings.
+
=item 1.11 - February 27, 2003
Add req->nargs to C API to distinguish between query string and
1.23 +113 -3 httpd-apreq/c/apache_request.c
Index: apache_request.c
===================================================================
RCS file: /home/cvs/httpd-apreq/c/apache_request.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- apache_request.c 27 Feb 2003 20:03:58 -0000 1.22
+++ apache_request.c 27 Feb 2003 21:30:10 -0000 1.23
@@ -240,6 +240,117 @@
return req;
}
+static char x2c(const char *what)
+{
+ register char digit;
+
+#ifndef CHARSET_EBCDIC
+ digit = ((what[0] >= 'A') ? ((what[0] & 0xdf) - 'A') + 10 : (what[0] -
'0'))
+;
+ digit *= 16;
+ digit += (what[1] >= 'A' ? ((what[1] & 0xdf) - 'A') + 10 : (what[1] -
'0'));
+#else /*CHARSET_EBCDIC*/
+ char xstr[5];
+ xstr[0]='0';
+ xstr[1]='x';
+ xstr[2]=what[0];
+ xstr[3]=what[1];
+ xstr[4]='\0';
+ digit = os_toebcdic[0xFF & ap_strtol(xstr, NULL, 16)];
+#endif /*CHARSET_EBCDIC*/
+ return (digit);
+}
+
+
+static unsigned int utf8_convert(char *str) {
+ long x = 0;
+ int i = 0;
+ while (i < 4 ) {
+ if ( ap_isxdigit(str[i]) != 0 ) {
+ if( ap_isdigit(str[i]) != 0 ) {
+ x = x * 16 + str[i] - '0';
+ }
+ else {
+ str[i] = tolower( str[i] );
+ x = x * 16 + str[i] - 'a' + 10;
+ }
+ }
+ else {
+ return 0;
+ }
+ i++;
+ }
+ if(i < 3)
+ return 0;
+ return (x);
+}
+
+static int ap_unescape_url_u(char *url)
+{
+ register int x, y, badesc, badpath;
+
+ badesc = 0;
+ badpath = 0;
+ for (x = 0, y = 0; url[y]; ++x, ++y) {
+ if (url[y] != '%'){
+ url[x] = url[y];
+ }
+ else {
+ if(url[y + 1] == 'u' || url[y + 1] == 'U'){
+ unsigned int c = utf8_convert(&url[y + 2]);
+ y += 5;
+ if(c < 0x80){
+ url[x] = c;
+ }
+ else if(c < 0x10000){
+ url[x] = (0xe0 | (c >> 12));
+ url[++x] = (0x80 | ((c >> 6) & 0x3f));
+ url[++x] = (0x80 | (c & 0x3f));
+ }
+ else if(c < 0x200000){
+ url[x] = 0xf0 | (c >> 18);
+ url[++x] = 0x80 | ((c >> 12) & 0x3f);
+ url[++x] = 0x80 | ((c >> 6) & 0x3f);
+ url[++x] = 0x80 | (c & 0x3f);
+ }
+ else if(c < 0x4000000){
+ url[x] = 0xf8 | (c >> 24);
+ url[++x] = 0x80 | ((c >> 18) & 0x3f);
+ url[++x] = 0x80 | ((c >> 12) & 0x3f);
+ url[++x] = 0x80 | ((c >> 6) & 0x3f);
+ url[++x] = 0x80 | (c & 0x3f);
+ }
+ else if(c < 0x8000000){
+ url[x] = 0xfe | (c >> 30);
+ url[++x] = 0x80 | ((c >> 24) & 0x3f);
+ url[++x] = 0x80 | ((c >> 18) & 0x3f);
+ url[++x] = 0x80 | ((c >> 12) & 0x3f);
+ url[++x] = 0x80 | ((c >> 6) & 0x3f);
+ url[++x] = 0x80 | (c & 0x3f);
+ }
+ }
+ else {
+ if (!ap_isxdigit(url[y + 1]) || !ap_isxdigit(url[y + 2])) {
+ badesc = 1;
+ url[x] = '%';
+ }
+ else {
+ url[x] = x2c(&url[y + 1]);
+ y += 2;
+ if (url[x] == '/' || url[x] == '\0')
+ badpath = 1;
+ }
+ }
+ }
+ }
+ url[x] = '\0';
+ if (badesc)
+ return BAD_REQUEST;
+ else if (badpath)
+ return NOT_FOUND;
+ else
+ return OK;
+}
static int urlword_dlm[] = {'&', ';', 0};
@@ -275,10 +386,9 @@
const char *key = ap_getword(r->pool, &val, '=');
req_plustospace((char*)key);
- ap_unescape_url((char*)key);
+ ap_unescape_url_u((char*)key);
req_plustospace((char*)val);
- ap_unescape_url((char*)val);
-
+ ap_unescape_url_u((char*)val);
ap_table_add(req->parms, key, val);
}
1.3 +2 -1 httpd-apreq/t/cookie.t
Index: cookie.t
===================================================================
RCS file: /home/cvs/httpd-apreq/t/cookie.t,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- cookie.t 27 Feb 2003 20:03:58 -0000 1.2
+++ cookie.t 27 Feb 2003 21:30:10 -0000 1.3
@@ -1,6 +1,7 @@
#!perl
use strict;
use Apache::src ();
+use LWP::UserAgent;
#use lib qw(lib blib/lib blib/arch);
eval 'require Apache::Cookie' or die $@;
#warn "No CGI::Cookie" and skip_test unless have_module "CGI::Cookie";
@@ -17,4 +18,4 @@
$request->header(Cookie => $cookie);
my $response = $ua->request($request, undef, undef);
print $response->content;
-
+
1.3 +4 -4 httpd-apreq/t/request-param.pl
Index: request-param.pl
===================================================================
RCS file: /home/cvs/httpd-apreq/t/request-param.pl,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- request-param.pl 27 Feb 2003 20:03:58 -0000 1.2
+++ request-param.pl 27 Feb 2003 21:30:10 -0000 1.3
@@ -24,8 +24,8 @@
print $/;
}
-for my $table ($apr->query_params, $apr->post_params) {
- my ($k,$v) = each %$table;
- print "param $k => $v$/";
-}
+#for my $table ($apr->query_params, $apr->post_params) {
+# my ($k,$v) = each %$table;
+# print "param $k => $v$/";
+#}
1.3 +0 -1 httpd-apreq/t/request.t
Index: request.t
===================================================================
RCS file: /home/cvs/httpd-apreq/t/request.t,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- request.t 27 Feb 2003 20:03:58 -0000 1.2
+++ request.t 27 Feb 2003 21:30:10 -0000 1.3
@@ -74,7 +74,6 @@
param ONE => ONE_value
param TWO => TWO_value
param THREE => M1,M2,M3
-param key => val
EOF
my $ok = $page eq $expect;
test ++$i, $ok;