Skip to content

Commit

Permalink
Fix more argument handling bugs
Browse files Browse the repository at this point in the history
Recognized JVM arguments all start with a dash. My original plan was to
make such dashes implicit, with the the Jaunch configurator adding
them... but upon reflection I think it's better for the TOML file to be
explicit. Otherwise, there is no way to properly support a JVM that
offers any non-dash-prefixed arguments.
  • Loading branch information
ctrueden committed Feb 6, 2024
1 parent 617557a commit 1bcac23
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 28 deletions.
52 changes: 26 additions & 26 deletions jaunch.toml
Original file line number Diff line number Diff line change
Expand Up @@ -131,32 +131,32 @@ supported-options = [
# mix and match to their hearts' content, being as sloppy as they want, and Jaunch will
# sort out the mess. As long as the JVM args are on the list here, of course.
recognized-jvm-args = [
'?',
'D*',
'X*',
'agentlib',
'agentpath',
'client',
'd32',
'd64',
'da',
'disableassertions',
'disablesystemassertions',
'dsa',
'ea',
'enableassertions',
'enablesystemassertions',
'esa',
'help',
'jar',
'javaagent',
'jre-restrict-search',
'no-jre-restrict-search',
'server',
'showversion',
'splash',
'verbose',
'version',
'-?',
'-D*',
'-X*',
'-agentlib',
'-agentpath',
'-client',
'-d32',
'-d64',
'-da',
'-disableassertions',
'-disablesystemassertions',
'-dsa',
'-ea',
'-enableassertions',
'-enablesystemassertions',
'-esa',
'-help',
'-jar',
'-javaagent',
'-jre-restrict-search',
'-no-jre-restrict-search',
'-server',
'-showversion',
'-splash',
'-verbose',
'-version',
]

# ==============================================================================
Expand Down
4 changes: 2 additions & 2 deletions src/commonMain/kotlin/Jaunch.kt
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ fun main(args: Array<String>) {
if (argVal != null) error("Divider symbol (--) does not accept a parameter")
if (i - 1 != divider) error("Divider symbol (--) may only be given once")
}
else if (argKey in supportedOptions) {
else if ((divider < 0 || i <= divider) && argKey in supportedOptions) {
// The argument is declared in Jaunch's configuration. Deal with it appropriately.
val option: JaunchOption = supportedOptions[argKey]!!
if (option.assignment == null) {
Expand Down Expand Up @@ -192,7 +192,7 @@ fun main(args: Array<String>) {
// No dash-dash divider was given, so we need to guess: is this a JVM arg, or a main arg?
(if (config.recognizes(argKey)) jvmArgs else mainArgs) += arg
}
else if (i < divider) {
else if (i <= divider) {
// This argument is before the dash-dash divider, so must be treated as a JVM arg.
// But we only allow it through if it's a recognized JVM argument, or the
// allow-unrecognized-jvm-args configuration flag is set to true.
Expand Down
20 changes: 20 additions & 0 deletions test/jy.t
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@ Test system property assignment.
$ ./jy-linux-x64 -Dcake=chocolate -c 'from java.lang import System; print(System.getProperty("cake"))'
chocolate

Test divider symbol handling.

$ ./jy-linux-x64 -- --dry-run 2>&1
Unknown option: -- or '--dry-run'
usage: jython [option] ... [-c cmd | -m mod | file | -] [arg] ...
Try 'jython -h' for more information.
[1]

$ ./jy-linux-x64 --dry-run --
/*/bin/java -Dpython.import.site=false -Dpython.cachedir.skip=true -Dpython.console.encoding=UTF-8 -Djava.class.path=/*/lib/jython-2.7.3.jar* -Xmx* org.python.util.jython (glob)

$ ./jy-linux-x64 --dry-run -Dfoo=before -- -Dfoo=after
/*/bin/java -Dfoo=before -Dpython.import.site=false -Dpython.cachedir.skip=true -Dpython.console.encoding=UTF-8 -Djava.class.path=/*/lib/jython-2.7.3.jar* -Xmx* org.python.util.jython -Dfoo=after (glob)

$ ./jy-linux-x64 -Dfoo=before -- -Dfoo=after -c 'from java.lang import System; print(System.getProperty("foo"))'
after

$ ./jy-linux-x64 bad -- good 2>&1 | head -n1
kotlin.IllegalStateException: Unrecognized JVM argument: bad

Test command line argument combinations.

$ ./jy-linux-x64 --help
Expand Down

0 comments on commit 1bcac23

Please sign in to comment.