Skip to content

[type: bug] Fix RewritePlugin placeholder drops first character and StringIndexOutOfBounds (#6883) - #7013

Open
zhang-arvin wants to merge 1 commit into
apache:masterfrom
zhang-arvin:fix/6883-rewrite-plugin
Open

[type: bug] Fix RewritePlugin placeholder drops first character and StringIndexOutOfBounds (#6883)#7013
zhang-arvin wants to merge 1 commit into
apache:masterfrom
zhang-arvin:fix/6883-rewrite-plugin

Conversation

@zhang-arvin

Copy link
Copy Markdown

Fixes #6883.

Bug Description

The RewritePlugin has two bugs in its placeholder branch:

  1. First character of path-variable value is dropped: rewriteUri.substring(rewriteHandle.getRegex().indexOf("{") + 1) skips the first character of the actual path-variable value because the +1 is meant to skip the { character in the regex pattern, but it's applied to the rewriteUri which has the actual value at that position.

  2. StringIndexOutOfBoundsException when regex lacks {: The condition only checks rewriteHandle.getReplace().contains("{") but not rewriteHandle.getRegex().contains("{"). When the replace pattern contains { but the regex doesn't, indexOf("{") returns -1, causing substring(-1) to throw.

Fix

  • Added rewriteHandle.getRegex().contains("{") to the guard condition
  • Removed the +1 offset from rewriteUri.substring() to preserve the first character

…tringIndexOutOfBounds (apache#6883)

Signed-off-by: zhang-arvin <arvin.zhang@htx-inc.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] RewritePlugin placeholder branch drops first character of path-variable value + StringIndexOutOfBounds when regex lacks {

1 participant