This is an automated email from the ASF dual-hosted git repository.

rmaucher pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/10.1.x by this push:
     new 3097902177 Fix some issues with rewrite processing from code review
3097902177 is described below

commit 3097902177a041a93476a036b9c8419b25d5cc0d
Author: remm <[email protected]>
AuthorDate: Thu Jul 16 14:11:50 2026 +0200

    Fix some issues with rewrite processing from code review
    
    N should really start from 0.
    C should start from after the last in the chain.
    qsd should always discard the original query string (already done on
    redirect).
    Remove code that tries to edit urlStringEncoded with a dubious index.
    Since it is reconstructed, there is no need to remove '?'.
    Avoid possible loop parsing the configuration on IOE.
---
 .../apache/catalina/valves/rewrite/RewriteValve.java   | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/java/org/apache/catalina/valves/rewrite/RewriteValve.java 
b/java/org/apache/catalina/valves/rewrite/RewriteValve.java
index 43777509e5..8c277e38b8 100644
--- a/java/org/apache/catalina/valves/rewrite/RewriteValve.java
+++ b/java/org/apache/catalina/valves/rewrite/RewriteValve.java
@@ -314,6 +314,7 @@ public class RewriteValve extends ValveBase {
                 }
             } catch (IOException ioe) {
                 containerLog.error(sm.getString("rewriteValve.readError"), 
ioe);
+                break;
             }
         }
         this.mapsConfiguration = mapsConfiguration;
@@ -477,11 +478,7 @@ public class RewriteValve extends ValveBase {
                                         
REWRITE_QUERY_ENCODER.encode(rewrittenQueryStringRewriteEncoded, uriCharset));
                                 urlStringEncoded.append('&');
                                 
urlStringEncoded.append(queryStringOriginalEncoded);
-                            } else if (index == urlStringEncoded.length() - 1) 
{
-                                // if the ? is the last character delete it, 
its only purpose was to
-                                // prevent the rewrite module from appending 
the query string
-                                urlStringEncoded.deleteCharAt(index);
-                            } else {
+                            } else if 
(!rewrittenQueryStringRewriteEncoded.isEmpty()) {
                                 urlStringEncoded.append('?');
                                 urlStringEncoded.append(
                                         
REWRITE_QUERY_ENCODER.encode(rewrittenQueryStringRewriteEncoded, uriCharset));
@@ -540,12 +537,15 @@ public class RewriteValve extends ValveBase {
 
                 // - chain (skip remaining chained rules if this one does not 
match)
                 if (rule.isChain() && newtest == null) {
-                    for (int j = i; j < rules.length; j++) {
+                    int skip = 0;
+                    for (int j = i + 1; j < rules.length; j++) {
                         if (!rules[j].isChain()) {
-                            i = j;
                             break;
+                        } else {
+                            skip++;
                         }
                     }
+                    i += skip;
                     continue;
                 }
                 // - last (stop rewriting here)
@@ -554,7 +554,7 @@ public class RewriteValve extends ValveBase {
                 }
                 // - next (redo again)
                 if (rule.isNext() && newtest != null) {
-                    i = 0;
+                    i = -1;
                     continue;
                 }
                 // - skip (n rules)
@@ -620,7 +620,7 @@ public class RewriteValve extends ValveBase {
                         
request.getCoyoteRequest().queryString().setChars(MessageBytes.EMPTY_CHAR_ARRAY,
 0, 0);
                         chunk = 
request.getCoyoteRequest().queryString().getCharChunk();
                         
chunk.append(REWRITE_QUERY_ENCODER.encode(queryStringRewriteEncoded, 
uriCharset));
-                        if (qsa && queryStringOriginalEncoded != null && 
!queryStringOriginalEncoded.isEmpty()) {
+                        if (!qsd && qsa && queryStringOriginalEncoded != null 
&& !queryStringOriginalEncoded.isEmpty()) {
                             chunk.append('&');
                             chunk.append(queryStringOriginalEncoded);
                         }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to