OSDN Git Service

bug fix.
authorvisor <visor@users.sourceforge.jp>
Mon, 2 Apr 2012 15:27:54 +0000 (00:27 +0900)
committervisor <visor@users.sourceforge.jp>
Mon, 2 Apr 2012 15:27:54 +0000 (00:27 +0900)
lib/http.cc
lib/util_apache.cc

index 46a9e44..b51120e 100644 (file)
@@ -3,6 +3,7 @@
 #include "motorenv.h"
 #include "motoroutput.h"
 #include "mlenv.h"
+#include "util_apache.h"
 #include "util_file.h"
 #include "util_string.h"
 #include "util_time.h"
@@ -43,6 +44,8 @@ void  HTTPResponse::printCookie (MotorOutput* out, MotorEnv* env) {
 
 void  HTTPResponse::setCookie (const ustring& key, const ustring& val, const ustring& path, time_t span, const ustring& domain, bool fsecure, MotorEnv* env) {
     ustring  ck;
+    ustring  u;
+    size_t  len;
     umatch  m;
     static uregex  re ("//|/\\.|\\.\\.|[\\x00-\\x20\\x7f-\\xff]");
     
@@ -51,28 +54,12 @@ void  HTTPResponse::setCookie (const ustring& key, const ustring& val, const ust
        ck.append (uEq);
        ck.append (cookieencode (val));
        ck.append (CharConst ("; path="));
-       if (path.size () == 0) {
-           if (env->scriptName.size () > 0) {
-               ck.append (dirPart (env->scriptName));
-           } else {
-               ck.append (uSlash);
-           }
-       } else {
-           if (usearch (path, m, re)) {
-               if (path.begin () == m[0].first) {
-                   ck.append (uSlash);
-               } else {
-                   ustring::const_iterator  b = path.begin ();
-                   if (path[0] != '/')
-                       ck.append (uSlash);
-                   ck.append (ustring (b, m[0].first));
-               }
-           } else {
-               if (path[0] != '/')
-                   ck.append (uSlash);
-               ck.append (path);
-           }
+       u = apacheAbsolutePath (path);
+       len = u.length ();
+       if (len > 0 && u[len - 1] == '/') {
+           u.resize (len - 1);
        }
+       ck.append (u);
        if (span > 0) {
            time_t  limit = now () + span;
            ck.append (CharConst ("; expires="));
@@ -465,12 +452,12 @@ ustring  HTTPSend::query (MlEnv* mlenv) {
 
 void  HTTPSend::writeQueryForm (MNode* e, TcpClient& out) {
     MNode*  a;
-    ustring  u;
     int  c = 0;
 
     if (e && e->isCons ()) {
        while (e) {
            if (a = e->car ()) {
+               ustring  u;
                if (c > 0)
                    u.append (uAmp);
                u.append (percentEncode (cv (to_string (a->car ()))));
@@ -506,13 +493,13 @@ void  HTTPSend::appendQueryForm (MNode* e, ustring& out) {
 
 size_t  HTTPSend::queryFormSize (MNode* e) {
     MNode*  a;
-    ustring  u;
     int  c = 0;
     size_t  ans = 0;
 
     if (e && e->isCons ()) {
        while (e) {
            if (a = e->car ()) {
+               ustring  u;
                if (c > 0)
                    u.append (uAmp);
                u.append (percentEncode (cv (to_string (a->car ()))));
index 18edce6..1b6bd67 100644 (file)
@@ -16,7 +16,7 @@ ustring  apacheAbsolutePath (const ustring& url) {
     bool  fdirpath;
     size_t  len = url.length ();
 
-    if (len > 0 && url[len - 1] == '/') {
+    if (len == 0 || url[len - 1] == '/') {
        fdirpath = true;
     } else {
        fdirpath = false;