-
Notifications
You must be signed in to change notification settings - Fork 950
Trim spaces around k and v to tolerate extra whitespace in build.properties #7585
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
Trim spaces around k and v to tolerate extra whitespace in build.properties #7585
Conversation
sbt
Outdated
@@ -707,6 +707,9 @@ loadConfigFile() { | |||
} | |||
|
|||
loadPropFile() { | |||
# trim key and value so as to be more forgiving with spaces around the '=': | |||
k=$(echo $k |sed -e 's/^\s*(.+)\s*$/\\1/g') | |||
v=$(echo $v |sed -e 's/^\s*(.+)\s*$/\\1/g') |
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.
Just wondering if it is possible to solve this with builtin bash functionality to avoid forking a new process. E.g. something like to replace all whitespaces https://stackoverflow.com/a/19661428/810109?
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.
Oh I just did it that way because I saw sed
was used elsewhere. Yes it looks like you can do this in plain bash. I wasn't able to get the above example working (it seems to replace all spaces, not just beginning and ending), but this approach seems to work:
str=" # 1.2.3 "
modStr="${str#"${str%%[![:space:]]*}"}"
modStr="${modStr%"${modStr##*[![:space:]]}"}"
echo "modStr is [$modStr]"
# prints '# 1.2.3'
That will work in POSIX compatible bashes.
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.
Ref: answer by Mateusz Piotrowski at SOF
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.
I pushed a new version using a function derived from the above.
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.
Thanks both!
@invadergir could you sign the Scala CLA please?
|
So sorry, I'm waiting on approval from our lawyer. I did this change while at work so they need to approve the CLA first. |
This is done. I guess the delay was because we were trying to get a corporate CLA and it seems this option doesn't exist anymore. I got approval to sign as an individual though. |
We noticed what looked like a bash error when using a build.properties that looked like this:
The error was:
I didn't realize
sbt
was a bash script, so I just added some whitespace trimming around the key and values insideloadPropFile()
. Now it is more forgiving of any spaces inserted around the '='. All these test cases now work as expected with no errors:I tested that spaces in front of the key are also trimmed as well, and of course if there is a '#' at the front (even with spaces in front of it), that is still ignored.
Hope this helps.