/hg/icedtea-web: Option parser now accept 0-n hyphens
jvanek at icedtea.classpath.org
jvanek at icedtea.classpath.org
Tue Oct 7 11:22:09 UTC 2014
changeset d1cc60519f24 in /hg/icedtea-web
details: http://icedtea.classpath.org/hg/icedtea-web?cmd=changeset;node=d1cc60519f24
author: Jiri Vanek <jvanek at redhat.com>
date: Tue Oct 07 13:21:47 2014 +0200
Option parser now accept 0-n hyphens
diffstat:
ChangeLog | 11 +++++
NEWS | 1 +
launcher/launchers.in | 2 +-
netx/net/sourceforge/jnlp/util/optionparser/OptionParser.java | 15 ++++---
tests/netx/unit/net/sourceforge/jnlp/util/optionparser/OptionParserTest.java | 19 ++++++++++
5 files changed, 40 insertions(+), 8 deletions(-)
diffs (94 lines):
diff -r 8071a44fe6de -r d1cc60519f24 ChangeLog
--- a/ChangeLog Fri Oct 03 14:20:40 2014 -0400
+++ b/ChangeLog Tue Oct 07 13:21:47 2014 +0200
@@ -1,3 +1,14 @@
+2014-09-22 Jiri Vanek <jvanek at redhat.com>
+
+ Option parser now accept 0-n hyphens
+ * launcher/launchers.in: regex matching for headless changed to * instead of 0-1
+ * netx/net/sourceforge/jnlp/util/optionparser/OptionParser.java: added new
+ method to removeLeadiingHyphens. (stringEqualsOption) now sanitize both inputs
+ by it.
+ * tests/netx/unit/net/sourceforge/jnlp/util/optionparser/OptionParserTest.java:
+ Added tests to verify none or more leading hyphens are correctly recognized.
+ Added tests to verify hyphens elsewhere will not confuse parser.
+
2014-10-03 Lukasz Dracz <ldracz at redhat.com>
IcedTea-Web Splashscreen allows zero or one hyphens preceding headless option
diff -r 8071a44fe6de -r d1cc60519f24 NEWS
--- a/NEWS Fri Oct 03 14:20:40 2014 -0400
+++ b/NEWS Tue Oct 07 13:21:47 2014 +0200
@@ -15,6 +15,7 @@
* JDK 8 support added (URLPermission granted if applicable)
* Added DE localisation
* Added KEY_ENABLE_MANIFEST_ATTRIBUTES_CHECK deployment property to control scan of Manifest file
+* starting arguments now accept also -- abbreviations
* Control Panel
- PR1856: ControlPanel UI improvement for lower resolutions (800*600)
* NetX
diff -r 8071a44fe6de -r d1cc60519f24 launcher/launchers.in
--- a/launcher/launchers.in Fri Oct 03 14:20:40 2014 -0400
+++ b/launcher/launchers.in Tue Oct 07 13:21:47 2014 +0200
@@ -53,7 +53,7 @@
*)
ARGS[$j]="$1"
j=$((j+1))
- if [[ "$1" =~ ^[-]{0,1}headless ]] ; then
+ if [[ "$1" =~ ^[-]*headless ]] ; then
SPLASH="false"
fi
;;
diff -r 8071a44fe6de -r d1cc60519f24 netx/net/sourceforge/jnlp/util/optionparser/OptionParser.java
--- a/netx/net/sourceforge/jnlp/util/optionparser/OptionParser.java Fri Oct 03 14:20:40 2014 -0400
+++ b/netx/net/sourceforge/jnlp/util/optionparser/OptionParser.java Tue Oct 07 13:21:47 2014 +0200
@@ -164,13 +164,14 @@
return mainArg;
}
- private boolean stringEqualsOption(String input, OptionsDefinitions.OPTIONS opt) {
- String option = opt.option.replaceAll("^-","").split("=")[0];
- input = input.replaceAll("^-","").split("=")[0];
- if (input.equals(option)) {
- return true;
- }
- return false;
+ protected static boolean stringEqualsOption(String input, OptionsDefinitions.OPTIONS opt) {
+ String option = removeLeadingHyphens(opt.option).split("=")[0];
+ input = removeLeadingHyphens(input).split("=")[0];
+ return input.equals(option);
+ }
+
+ private static String removeLeadingHyphens(final String input) {
+ return input.replaceAll("^-*", "");
}
public boolean hasOption(OptionsDefinitions.OPTIONS option) {
diff -r 8071a44fe6de -r d1cc60519f24 tests/netx/unit/net/sourceforge/jnlp/util/optionparser/OptionParserTest.java
--- a/tests/netx/unit/net/sourceforge/jnlp/util/optionparser/OptionParserTest.java Fri Oct 03 14:20:40 2014 -0400
+++ b/tests/netx/unit/net/sourceforge/jnlp/util/optionparser/OptionParserTest.java Tue Oct 07 13:21:47 2014 +0200
@@ -397,4 +397,23 @@
assertEquals(3, values.indexOf("yellow"));
assertEquals("red", parser.getMainArg());
}
+
+ @Test
+ public void testOptionsSyntaxPositive() {
+ assertTrue(OptionParser.stringEqualsOption("headless", OptionsDefinitions.OPTIONS.HEADLESS));
+ assertTrue(OptionParser.stringEqualsOption("-headless", OptionsDefinitions.OPTIONS.HEADLESS));
+ assertTrue(OptionParser.stringEqualsOption("--headless", OptionsDefinitions.OPTIONS.HEADLESS));
+ assertTrue(OptionParser.stringEqualsOption("---headless", OptionsDefinitions.OPTIONS.HEADLESS));
+ }
+
+ @Test
+ public void testOptionsSyntaxNegative() {
+ assertFalse(OptionParser.stringEqualsOption(" -headless", OptionsDefinitions.OPTIONS.HEADLESS));
+ assertFalse(OptionParser.stringEqualsOption("h-eadless", OptionsDefinitions.OPTIONS.HEADLESS));
+ assertFalse(OptionParser.stringEqualsOption("headless-", OptionsDefinitions.OPTIONS.HEADLESS));
+ assertFalse(OptionParser.stringEqualsOption("- -headless", OptionsDefinitions.OPTIONS.HEADLESS));
+ assertFalse(OptionParser.stringEqualsOption("--- ---headless", OptionsDefinitions.OPTIONS.HEADLESS));
+ assertFalse(OptionParser.stringEqualsOption("- ---headless", OptionsDefinitions.OPTIONS.HEADLESS));
+ assertFalse(OptionParser.stringEqualsOption("--- -headless", OptionsDefinitions.OPTIONS.HEADLESS));
+ }
}
\ No newline at end of file
More information about the distro-pkg-dev
mailing list