Skip to content
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

Windows start script interprets commas (,) and splits arguments where it should just pass them to the application #1650

Open
mpollmeier opened this issue Nov 20, 2024 · 3 comments
Labels

Comments

@mpollmeier
Copy link

mpollmeier commented Nov 20, 2024

Expected behaviour

Commas (,) in arguments should be handed over to the application rather than interpreted by the start script.

Actual behaviour

For the linux start script, that's the case.
The windows starter script interprets the comma and splits it up into separate arguments.

Way to reproduce

mkdir -p project src/main/scala
echo 'sbt.version=1.10.5' > project/build.properties
echo 'addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.10.4")' > project/plugins.sbt
echo 'enablePlugins(JavaAppPackaging)' > build.sbt
echo 'object Foo { 
  def main(args: Array[String]) = { 
    println(args.size)
    args.foreach(println) 
  }
}' > Foo.scala
sbt stage

# on linux:
target/universal/stage/bin/native-packager-demo a b,bb c
3
a
b,bb
c

# on windows:
.\target\universal\stage\bin\native-packager-demo.bat a b,bb c
4
a
b
bb
c

Workaround: triple double-quotes

.\target\universal\stage\bin\native-packager-demo.bat a """b,bb""" c
3
a
b,bb
c

Extra context

This is not a windows powershell issue - the below works correctly on both linux and windows:

echo 'class Bar {
  public static void main(String[] args) {
    System.out.println(args.length);
    for (String arg : args) { 
      System.out.println(arg);
    }
  }
}' > Bar.java

java Bar.java a b,bb c
# output on both linux and windows:
3
a
b,bb
c
@mpollmeier mpollmeier changed the title Windows start script interprets commas (,) and splits arguments, where it should just leave them alone Windows start script interprets commas (,) and splits arguments where it should just pass them to the application Nov 20, 2024
@mpollmeier
Copy link
Author

mpollmeier commented Nov 20, 2024

Looks like shift (or rather %%0!?) might be to blame. Here's a simplified version of the script that shows how shift splits up the args on whitespace as well as comma ,:

@setlocal enabledelayedexpansion
@echo off

call :process_args a b,bb c
@endlocal

exit /B 0

:process_args
  shift
  call set _PARAM1=%%0
  echo PARAM1=%_PARAM1%
  shift
  call set _PARAM1=%%0
  echo PARAM1=%_PARAM1%
  shift
  call set _PARAM1=%%0
  echo PARAM1=%_PARAM1%
  shift
  call set _PARAM1=%%0
  echo PARAM1=%_PARAM1%

output:

PARAM1=a
PARAM1=b
PARAM1=bb
PARAM1=c

@mpollmeier
Copy link
Author

Hmm, so according to https://stackoverflow.com/a/8145923 commas are separators for arguments in windows, so this behaviour is actually expected. If we use %~0 instead of %%0 it would at least work if the parameter was quoted ("b,bb"). That change would probably be worthwhile and simplify the workaround (only one quote instead of three). The main issue will remain though, it's the nature of windows batch files.

Let me know if you want to keep this open for discussion, otherwise we can close this issue.

@muuki88 muuki88 added the windows label Dec 2, 2024
@muuki88
Copy link
Contributor

muuki88 commented Dec 2, 2024

Hi @mpollmeier

Thanks for the detailed description and follow up of your findings 🙏 ❤️

I can't speak for any windows users as I never had to shipped on windows or coded on windows. I'm happy to merge your suggestion, if you want to provide a PR 😊

If we use %~0 instead of %%0 it would at least work if the parameter was quoted ("b,bb"). That change would probably be worthwhile and simplify the workaround (only one quote instead of three)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants