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

Allow unrecognized options in config file #3967

Merged
merged 1 commit into from
Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions common/src/main/java/bisq/common/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,12 @@ public Config(String defaultAppName, File defaultUserDataDir, String... args) {
OptionSet cliOpts = parser.parse(args);
options.addOptionSet(cliOpts);

// Option parsing is strict at the command line, but we relax it now for any
// subsequent config file processing. This is for compatibility with pre-1.2.6
// versions that allowed unrecognized options in the bisq.properties config
// file and because it follows suit with Bitcoin Core's config file behavior.
parser.allowsUnrecognizedOptions();

// Parse config file specified at the command line only if it was specified as
// an absolute path. Otherwise, the config file will be processed later below.
File configFile = null;
Expand Down
11 changes: 11 additions & 0 deletions common/src/test/java/bisq/common/config/ConfigTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ public void whenUnrecognizedOptionIsSet_thenConfigExceptionIsThrown() {
configWithOpts(opt("bogus"));
}

@Test
public void whenUnrecognizedOptionIsSetInConfigFile_thenNoExceptionIsThrown() throws IOException {
File configFile = File.createTempFile("bisq", "properties");
try (PrintWriter writer = new PrintWriter(configFile)) {
writer.println(new ConfigFileOption("bogusOption", "bogusValue"));
writer.println(new ConfigFileOption(APP_NAME, "BisqTest"));
}
Config config = configWithOpts(opt(CONFIG_FILE, configFile.getAbsolutePath()));
assertThat(config.appName, equalTo("BisqTest"));
}

@Test
public void whenOptionFileArgumentDoesNotExist_thenConfigExceptionIsThrown() {
String filepath = "/does/not/exist";
Expand Down