Skip to content

Commit

Permalink
#289 Fix single part locale crash
Browse files Browse the repository at this point in the history
  • Loading branch information
rheimus committed Jan 15, 2022
1 parent 9e051d9 commit c2d9371
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,13 @@ public static void forServer(Path json) throws IOException {
hasMissingEntries = true;
}

String[] localeParts = getString(misc, PROP_LOCALE, "en_US").split("_");
config.LOCALE = new Locale(localeParts[0], localeParts[1]);
String locale = getString(misc, PROP_LOCALE, "en_US");
if (locale.contains("_")) {
String[] localeParts = getString(misc, PROP_LOCALE, "en_US").split("_");
config.LOCALE = new Locale(localeParts[0], localeParts[1]);
} else {
config.LOCALE = new Locale(locale);
}

if (hasMissingEntries) {
// Generate a new config if we failed to read parts of it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void beforeEach() {
}

@ParameterizedTest
@DisplayName("Parsing")
@DisplayName("Should parse")
@ValueSource(strings = {"src/test/resources/server-config.json"})
void parseServerConfig(Path file) {
ServerSync.MODE = EServerMode.SERVER;
Expand All @@ -36,4 +36,18 @@ void parseServerConfig(Path file) {
e.printStackTrace();
}
}

@ParameterizedTest
@DisplayName("Should parse single part locales")
@ValueSource(strings = {"src/test/resources/server-single-part-locale-config.json"})
void parseSinglePartLocale(Path file) {
ServerSync.MODE = EServerMode.SERVER;
try {
JsonConfig.forServer(file);
SyncConfig config = SyncConfig.getConfig();
assertNotNull(config.LOCALE);
} catch (IOException e) {
e.printStackTrace();
}
}
}
45 changes: 45 additions & 0 deletions src/test/resources/server-single-part-locale-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"general": {
"push_client_mods": false,
"sync_mode": 2
},
"connection": {
"port": 38067,
"buffer": 65536
},
"rules": {
"directories": [
{
"path": "test-mirror",
"mode": "mirror"
},
{
"path": "test-push",
"mode": "push"
},
"test-default"
],
"files": {
"include": [],
"ignore": [
{
"description": "No jar files allowed",
"pattern": "**/*.jar"
},
{
"pattern": "**/other.bing"
},
"**/basic.thing"
],
"redirect": [
{
"pattern": "**/*.jar",
"redirectTo": "redirected-files"
}
]
}
},
"misc": {
"locale": "en"
}
}

0 comments on commit c2d9371

Please sign in to comment.