Skip to content

Conversation

invadergir
Copy link
Contributor

@invadergir invadergir commented Jun 20, 2024

We noticed what looked like a bash error when using a build.properties that looked like this:

sbt.version= 1.10.0

The error was:

/opt/sbt/bin/sbt: line 754: ((: 1.10.0 >= 2 : syntax error: invalid arithmetic operator (error token is ".10.0 >= 2 ")
/opt/sbt/bin/sbt: line 754: ((: 1.10.0 >= 1 : syntax error: invalid arithmetic operator (error token is ".10.0 >= 1 ")
false

I didn't realize sbt was a bash script, so I just added some whitespace trimming around the key and values inside loadPropFile(). Now it is more forgiving of any spaces inserted around the '='. All these test cases now work as expected with no errors:

sbt.version= 1.10.0
sbt.version =1.10.0
sbt.version = 1.10.0

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.

@invadergir invadergir marked this pull request as ready for review June 20, 2024 18:15
@invadergir invadergir changed the title Trim spaces around k and v in build.properties to be more forgiving. Trim spaces around k and v to tolerate extra whitespace in build.properties Jun 20, 2024
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')
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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.

@invadergir invadergir changed the title Trim spaces around k and v to tolerate extra whitespace in build.properties Trim spaces around k and v to tolerate extra whitespace in build.properties (fix for bug #7587) Jun 21, 2024
@invadergir invadergir changed the title Trim spaces around k and v to tolerate extra whitespace in build.properties (fix for bug #7587) Trim spaces around k and v to tolerate extra whitespace in build.properties Jun 21, 2024
Copy link
Member

@eed3si9n eed3si9n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks both!

@eed3si9n
Copy link
Member

eed3si9n commented Jul 7, 2024

@invadergir could you sign the Scala CLA please?

Pull request submitted by invadergir
CLA check for invadergir failed
Please sign the Scala CLA to contribute to the Scala compiler.
Go to https://www.lightbend.com/contribute/cla/scala and then
comment on the pull request to ask for a new check.

@invadergir
Copy link
Contributor Author

@invadergir could you sign the Scala CLA please?

Pull request submitted by invadergir
CLA check for invadergir failed
Please sign the Scala CLA to contribute to the Scala compiler.
Go to https://www.lightbend.com/contribute/cla/scala and then
comment on the pull request to ask for a new check.

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.

@invadergir
Copy link
Contributor Author

@invadergir could you sign the Scala CLA please?

Pull request submitted by invadergir
CLA check for invadergir failed
Please sign the Scala CLA to contribute to the Scala compiler.
Go to https://www.lightbend.com/contribute/cla/scala and then
comment on the pull request to ask for a new check.

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.

@eed3si9n eed3si9n merged commit 2f93629 into sbt:1.10.x Aug 8, 2024
10 checks passed
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.

3 participants