--- mod_include.c	Wed Jul  9 12:12:27 2003
+++ mod_include.c.patch	Wed Jul  9 12:12:32 2003
@@ -478,8 +478,14 @@
         if (len)
         {
             pos = bndm(str, slen, c, len, ctx->start_seq_pat);
+
             if (pos != len)
             {
+                if ((buf < c) && (*(buf+pos) != str[0]) && (*(c+pos) == str[0]))
+                {
+                    pos += (c - buf);
+                }
+
                 ctx->head_start_bucket = dptr;
                 ctx->head_start_index = pos;
                 ctx->bytes_parsed += pos + slen;
@@ -2916,6 +2922,7 @@
     include_ctx_t *ctx = f->ctx;
     apr_bucket *dptr = APR_BRIGADE_FIRST(*bb);
     apr_bucket *tmp_dptr;
+    apr_bucket *last_dptr = NULL;
     apr_bucket_brigade *tag_and_after;
     apr_status_t rv = APR_SUCCESS;
 
@@ -2998,6 +3005,7 @@
             else if (tmp_dptr == NULL) { 
                 /* There was no possible SSI tag in the
                  * remainder of this brigade... */
+                last_dptr = dptr;
                 dptr = APR_BRIGADE_SENTINEL(*bb);  
             }
         }
@@ -3141,11 +3149,8 @@
             if (content_head == NULL) {
                 content_head = dptr;
             }
-            tmp_dptr = ctx->head_start_bucket;
-            if (!APR_BRIGADE_EMPTY(ctx->ssi_tag_brigade)) {
-                apr_brigade_cleanup(ctx->ssi_tag_brigade);
-            }
-            else {
+            if (APR_BRIGADE_EMPTY(ctx->ssi_tag_brigade)) {
+                tmp_dptr = ctx->head_start_bucket;
                 do {
                     tmp_bkt  = tmp_dptr;
                     tmp_dptr = APR_BUCKET_NEXT (tmp_dptr);
@@ -3153,6 +3158,7 @@
                 } while ((tmp_dptr != content_head) &&
                          (tmp_dptr != APR_BRIGADE_SENTINEL(*bb)));
             }
+
             if (ctx->combined_tag == tmp_buf) {
                 ctx->combined_tag = NULL;
             }
@@ -3197,6 +3203,24 @@
      *   once the whole tag has been found.
      */
     if (ctx->state == PRE_HEAD) {
+        /* Since, in the case where the last SSI was a conditional (if, elif
+         *   or else), the find_start_sequence will return tmp_dptr==NULL,
+         *   then dptr was explicitly set to APR_BRIGADE_SENTINEL, so the
+         *   second if code below would never work properly.  Now, we've
+         *   added last_dptr, set only in this case and we delete it here.
+         */
+        if ((dptr == APR_BRIGADE_SENTINEL(*bb)) &&
+            (!(ctx->flags & FLAG_PRINTING)) && (last_dptr != NULL)) {
+            apr_bucket *free_bucket;
+            do {
+                free_bucket = last_dptr;
+                last_dptr = APR_BUCKET_NEXT (last_dptr);
+                apr_bucket_delete(free_bucket);
+            } while (last_dptr != dptr);
+        }
+        /* The following code just seems wrong.  It's left here in case it
+         *   it some how correct, but the previous if seems more correct
+         */
         /* Inside a false conditional (if, elif, else), so toss it all... */
         if ((dptr != APR_BRIGADE_SENTINEL(*bb)) &&
             (!(ctx->flags & FLAG_PRINTING))) {
