Skip to content

Fix IndexOutOfBoundsException for non-existing groups in fn:replace#2698

Merged
ChristianGruen merged 1 commit into
BaseXdb:mainfrom
GuntherRademacher:#2698
Jun 21, 2026
Merged

Fix IndexOutOfBoundsException for non-existing groups in fn:replace#2698
ChristianGruen merged 1 commit into
BaseXdb:mainfrom
GuntherRademacher:#2698

Conversation

@GuntherRademacher

Copy link
Copy Markdown
Member

As reported by Amanda Galtman on basex-talk, an IndexOutOfBoundsException can occur when the replacement string contains a reference to a non-existing capture group that is preceded by a backslash, e.g.

replace('full stop.','\.','\\$1')

The issue is caused by FnReplace.item, which only examines the single character preceding a dollar sign. If that character is a backslash, the dollar sign is assumed to be escaped, and the replacement string is subsequently passed to Matcher.replaceAll.

The fix is to count the number of consecutive preceding backslashes. The dollar sign is escaped only if that count is odd.

@ChristianGruen

Copy link
Copy Markdown
Member

Thank you

@ChristianGruen ChristianGruen merged commit 2c8748e into BaseXdb:main Jun 21, 2026
1 check passed
@ChristianGruen ChristianGruen deleted the #2698 branch June 21, 2026 05:51
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.

2 participants