]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
mod_rewrite: Follow up to r1919325: Simplify QSLAST tracking.
authorYann Ylavic <ylavic@apache.org>
Wed, 11 Sep 2024 14:13:54 +0000 (14:13 +0000)
committerYann Ylavic <ylavic@apache.org>
Wed, 11 Sep 2024 14:13:54 +0000 (14:13 +0000)
We don't need to loop to skip the safe qmarks (thanks rpluem!).

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1920566 13f79535-47bb-0310-9956-ffa450edef68

modules/mappers/mod_rewrite.c

index 10ba41a9b5c09edc691a24a1aec3390576928341..413eb417c2566fb33c142320cd35f8681fc31dbf 100644 (file)
@@ -2429,21 +2429,19 @@ static char *do_expand(char *input, rewrite_ctx *ctx, rewriterule_entry *entry,
             *unsafe_qmark = 0;
 
             /* keep tracking only if interested in the last qmark */
-            if (entry && (entry->flags & RULEFLAG_QSLAST)) {
-                do {
-                    span++;
-                    span += strcspn(input + span, EXPAND_SPECIALS "?");
-                } while (input[span] == '?');
-            }
-            else {
+            if (!entry || !(entry->flags & RULEFLAG_QSLAST)) {
                 unsafe_qmark = NULL;
-                span += strcspn(input + span, EXPAND_SPECIALS);
             }
+
+            /* find the next real special char, any (last) qmark up to
+             * there is safe too
+             */
+            span += strcspn(input + span, EXPAND_SPECIALS);
         }
     }
 
-    /* fast exit */
-    if (inputlen == span) {
+    /* fast path (no specials) */
+    if (span >= inputlen) {
         return apr_pstrmemdup(pool, input, inputlen);
     }
 
@@ -2625,16 +2623,14 @@ static char *do_expand(char *input, rewrite_ctx *ctx, rewriterule_entry *entry,
                 *unsafe_qmark = 0;
 
                 /* keep tracking only if interested in the last qmark */
-                if (entry && (entry->flags & RULEFLAG_QSLAST)) {
-                    do {
-                        span++;
-                        span += strcspn(p + span, EXPAND_SPECIALS "?");
-                    } while (p[span] == '?');
-                }
-                else {
+                if (!entry || !(entry->flags & RULEFLAG_QSLAST)) {
                     unsafe_qmark = NULL;
-                    span += strcspn(p + span, EXPAND_SPECIALS);
                 }
+
+                /* find the next real special char, any (last) qmark up to
+                 * there is safe too
+                 */
+                span += strcspn(p + span, EXPAND_SPECIALS);
             }
         }
         if (span > 0) {