Skip to content

Commit

Permalink
[MWRAPPER-111] Trim whitespace when reading from properties file
Browse files Browse the repository at this point in the history
  • Loading branch information
mhalbritter authored and slachiewicz committed Dec 14, 2024
1 parent 8a43246 commit 6e24460
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions maven-wrapper-distribution/src/resources/mvnw
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
export MAVEN_PROJECTBASEDIR
log "$MAVEN_PROJECTBASEDIR"

trim() {
# MWRAPPER-139:
# Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds.
# Needed for removing poorly interpreted newline sequences when running in more
# exotic environments such as mingw bash on Windows.
printf "%s" "${1}" | tr -d '[:space:]'
}

##########################################################################################
# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
# This allows using the maven wrapper in projects that prohibit checking in binary data.
Expand All @@ -217,10 +225,8 @@ else
wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/@@project.version@@/maven-wrapper-@@project.version@@.jar"
fi
while IFS="=" read -r key value; do
# Remove '\r' from value to allow usage on windows as IFS does not consider '\r' as a separator ( considers space, tab, new line ('\n'), and custom '=' )
safeValue=$(echo "$value" | tr -d '\r')
case "$key" in wrapperUrl)
wrapperUrl="$safeValue"
wrapperUrl=$(trim "${value-}")
break
;;
esac
Expand Down Expand Up @@ -276,7 +282,7 @@ fi
wrapperSha256Sum=""
while IFS="=" read -r key value; do
case "$key" in wrapperSha256Sum)
wrapperSha256Sum=$value
wrapperSha256Sum=$(trim "${value-}")
break
;;
esac
Expand Down

0 comments on commit 6e24460

Please sign in to comment.