Skip to content

Escape '{' in StringEscapeUtils.ESCAPE_XSI - #783

Open
dxbjavid wants to merge 1 commit into
apache:masterfrom
dxbjavid:escape-xsi-brace
Open

dxbjavid wants to merge 1 commit into
apache:masterfrom
dxbjavid:escape-xsi-brace

Conversation

@dxbjavid

Copy link
Copy Markdown
Contributor

StringEscapeUtils.ESCAPE_XSI backslash-escapes shell metacharacters but leaves { alone, so bash and zsh still apply brace expansion to the escaped value. escapeXSI("{report.txt,-delete}") comes back unchanged, and bash -c "find . -name " + escaped runs find . -name report.txt -delete: one escaped value becomes two arguments, and the second is an option chosen by whoever supplied the input.

Repro, before the fix: bash -c "printf '<%s>\n' " + escapeXSI("{report.txt,-delete}") prints <report.txt> and <-delete>. After the fix it prints one argument, <{report.txt,-delete}>. Escaping { alone stops the expansion, the same way the map escapes [ but not ]. UNESCAPE_XSI already round-trips \{.

The new assertions in StringEscapeUtilsTest#testEscapeXSI fail without the main change and pass with it. The default mvn build is green.


  • Read the contribution guidelines for this project.
  • Read the ASF Generative Tooling Guidance if you use Artificial Intelligence (AI).
  • I used AI to create any part of, or all of, this pull request. Which AI tool was used to create this pull request, and to what extent did it contribute? Claude Code
  • Run a successful build using the default Maven goal with mvn; that's mvn on the command line by itself.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. This may not always be possible, but it is a best practice.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body. Note that a maintainer may squash commits during the merge process.

An unescaped '{' lets bash and zsh brace-expand the escaped value, so
escapeXSI("{report.txt,-delete}") still expands to two words when the
result is passed to bash -c.
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.

1 participant