-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Avoid parsing MAVEN_OPTS (master/4.x) #10970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Fixes apache#10937 by introducing an additional INTERNAL_MAVEN_OPTS for any arguments that need to be inserted by the script. Parsing the externally-defined MAVEN_OPTS variable can lead to incorrect processing of quotes and special characters, so use the separate variable to avoid doing so. Additionally JVM_CONFIG_MAVEN_OPTS is introduced as its own variable to preserve the append behaviour.
Remove quotes from the new JVM_CONFIG_MAVEN_OPTS to also allow quoted pipes to work from jvm.config This is a follow-up to apache#10937, where the extra layer of quotes causes parsing issues in Windows cmd
Test that adding pipes to either MAVEN_OPTS or jvm.config does not break anything Note: it is important that a jvm.config exists for the MAVEN_OPTS portion of the test to work
|
Sorry, I think I did a rename of the folder before the last push that moved it over the line length limit. Fixed now. |
...ore-it-suite/src/test/java/org/apache/maven/it/MavenITgh10937QuotedPipesInMavenOptsTest.java
Show resolved
Hide resolved
|
Looks like in 4.x the bash script also changed, such that it now The changes made here (purely to the Windows .cmd!) should have no impact on that, but the new tests do expose that issue. I'll consolidate findings/discussion back in issue #10937 but I'm honestly not too sure what to do here -- complex bash scripts are not my forte. |
Fixes apache#10937 by introducing an additional INTERNAL_MAVEN_OPTS for any arguments that need to be inserted by the script. Parsing the externally-defined MAVEN_OPTS variable can lead to incorrect processing of quotes and special characters, so use the separate variable to avoid doing so.
|
@gnodet Since you made the original change in #2213, could I run this by you, as I'm a bit unsure. The existing behaviour is:
But the behaviour seen with pipes specifically is that the quotes are being stripped but not added back in. i.e.
I'm leaning towards using option 2, but I'm not familiar enough with either this area of code nor bash to be certain that it won't cause other issues. Do you have any suggestions here? Proposed new concat_lines() {
if [ -f "$1" ]; then
# First convert all CR to LF using tr
tr '\r' '\n' < "$1" | \
sed -e '/^$/d' -e 's/#.*$//' | \
# Replace LF with NUL for xargs
tr '\n' '\0' | \
# Split into words and process each argument
# Use -0 with NUL to avoid special behaviour on quotes
xargs -n 1 -0 | \
while read -r arg; do
# Replace variables first
arg=$(echo "$arg" | sed \
-e "s@\${MAVEN_PROJECTBASEDIR}@$MAVEN_PROJECTBASEDIR@g" \
-e "s@\$MAVEN_PROJECTBASEDIR@$MAVEN_PROJECTBASEDIR@g")
echo "$arg"
done | \
tr '\n' ' '
fi
}e: This proposed new version passes both the new gh10937 test and the old mng4559 tests. So as far as what's tested, it appears to work correctly. I'll push the change to the PR but happy to rollback if it's the wrong approach. e2: I just realised |
By default xargs handles quotes specially. To avoid this behaviour, `-0` must be used instead, but first we need to convert LF to NUL. Since quotes are no longer being stripped by xargs, we should also stop trying to add them back in otherwise nested quotes cause further issues
|
So um... what's the next step here? Is there anything else I should do here or on the related 3.9.x PR? Also, what's the best way to get this into 4.0.x branch? I think the changes should be identical, should I wait for this one to be reviewed/merged first? |
gnodet
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thx for this nice patch ! I'll do the backport to maven-4.0.x branch.
Fixes apache#10937 by introducing an additional INTERNAL_MAVEN_OPTS for any arguments that need to be inserted by the script. Parsing the externally-defined MAVEN_OPTS variable can lead to incorrect processing of quotes and special characters, so use the separate variable to avoid doing so. Additionally JVM_CONFIG_MAVEN_OPTS is introduced as its own variable to preserve the append behaviour. Remove quotes from the new JVM_CONFIG_MAVEN_OPTS to also allow quoted pipes to work from jvm.config This is a follow-up to apache#10937, where the extra layer of quotes causes parsing issues in Windows cmd Test that adding pipes to either MAVEN_OPTS or jvm.config does not break anything Note: it is important that a jvm.config exists for the MAVEN_OPTS portion of the test to work By default xargs handles quotes specially. To avoid this behaviour, `-0` must be used instead, but first we need to convert LF to NUL. Since quotes are no longer being stripped by xargs, we should also stop trying to add them back in otherwise nested quotes cause further issues --------- Co-authored-by: Bob <BobVul@users.noreply.github.com> (cherry picked from commit aeff353)
💚 All backports created successfully
Questions ?Please refer to the Backport tool documentation |
Thank you! Should the 3.9.x IT also be merged? apache/maven-integration-testing#407 |
Fixes #10937 by introducing an additional INTERNAL_MAVEN_OPTS for any arguments that need to be inserted by the script. Parsing the externally-defined MAVEN_OPTS variable can lead to incorrect processing of quotes and special characters, so use the separate variable to avoid doing so. Additionally JVM_CONFIG_MAVEN_OPTS is introduced as its own variable to preserve the append behaviour. Remove quotes from the new JVM_CONFIG_MAVEN_OPTS to also allow quoted pipes to work from jvm.config This is a follow-up to #10937, where the extra layer of quotes causes parsing issues in Windows cmd Test that adding pipes to either MAVEN_OPTS or jvm.config does not break anything Note: it is important that a jvm.config exists for the MAVEN_OPTS portion of the test to work By default xargs handles quotes specially. To avoid this behaviour, `-0` must be used instead, but first we need to convert LF to NUL. Since quotes are no longer being stripped by xargs, we should also stop trying to add them back in otherwise nested quotes cause further issues --------- (cherry picked from commit aeff353) Co-authored-by: Bob <1674237+BobVul@users.noreply.github.com> Co-authored-by: Bob <BobVul@users.noreply.github.com>
Fixes apache#10937 by introducing an additional INTERNAL_MAVEN_OPTS for any arguments that need to be inserted by the script. Parsing the externally-defined MAVEN_OPTS variable can lead to incorrect processing of quotes and special characters, so use the separate variable to avoid doing so. Additionally JVM_CONFIG_MAVEN_OPTS is introduced as its own variable to preserve the append behaviour. Remove quotes from the new JVM_CONFIG_MAVEN_OPTS to also allow quoted pipes to work from jvm.config This is a follow-up to apache#10937, where the extra layer of quotes causes parsing issues in Windows cmd Test that adding pipes to either MAVEN_OPTS or jvm.config does not break anything Note: it is important that a jvm.config exists for the MAVEN_OPTS portion of the test to work By default xargs handles quotes specially. To avoid this behaviour, `-0` must be used instead, but first we need to convert LF to NUL. Since quotes are no longer being stripped by xargs, we should also stop trying to add them back in otherwise nested quotes cause further issues --------- Co-authored-by: Bob <BobVul@users.noreply.github.com>
should 😄 done |
Fixes #10937 by introducing an additional INTERNAL_MAVEN_OPTS for any arguments that need to be inserted by the script. Parsing the externally-defined MAVEN_OPTS variable can lead to incorrect processing of quotes and special characters, so use the separate variable to avoid doing so.
Additionally JVM_CONFIG_MAVEN_OPTS is introduced as its own variable to preserve the append behaviour.
Specifically, this fixes this case:
by implementing proposed fix 2 from #10937
The related fix for 3.9.x branch is in PR #10969
Following this checklist to help us incorporate your
contribution quickly and easily:
Note that commits might be squashed by a maintainer on merge.
This may not always be possible but is a best-practice.
mvn verifyto make sure basic checks pass.A more thorough check will be performed on your pull request automatically.
If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.
To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.