Skip to content

Commit c2d9371

Browse files
committed
#289 Fix single part locale crash
1 parent 9e051d9 commit c2d9371

File tree

3 files changed

+67
-3
lines changed

3 files changed

+67
-3
lines changed

src/main/java/com/superzanti/serversync/config/JsonConfig.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,13 @@ public static void forServer(Path json) throws IOException {
114114
hasMissingEntries = true;
115115
}
116116

117-
String[] localeParts = getString(misc, PROP_LOCALE, "en_US").split("_");
118-
config.LOCALE = new Locale(localeParts[0], localeParts[1]);
117+
String locale = getString(misc, PROP_LOCALE, "en_US");
118+
if (locale.contains("_")) {
119+
String[] localeParts = getString(misc, PROP_LOCALE, "en_US").split("_");
120+
config.LOCALE = new Locale(localeParts[0], localeParts[1]);
121+
} else {
122+
config.LOCALE = new Locale(locale);
123+
}
119124

120125
if (hasMissingEntries) {
121126
// Generate a new config if we failed to read parts of it

src/test/java/com/superzanti/serversync/config/JsonConfigTest.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void beforeEach() {
1919
}
2020

2121
@ParameterizedTest
22-
@DisplayName("Parsing")
22+
@DisplayName("Should parse")
2323
@ValueSource(strings = {"src/test/resources/server-config.json"})
2424
void parseServerConfig(Path file) {
2525
ServerSync.MODE = EServerMode.SERVER;
@@ -36,4 +36,18 @@ void parseServerConfig(Path file) {
3636
e.printStackTrace();
3737
}
3838
}
39+
40+
@ParameterizedTest
41+
@DisplayName("Should parse single part locales")
42+
@ValueSource(strings = {"src/test/resources/server-single-part-locale-config.json"})
43+
void parseSinglePartLocale(Path file) {
44+
ServerSync.MODE = EServerMode.SERVER;
45+
try {
46+
JsonConfig.forServer(file);
47+
SyncConfig config = SyncConfig.getConfig();
48+
assertNotNull(config.LOCALE);
49+
} catch (IOException e) {
50+
e.printStackTrace();
51+
}
52+
}
3953
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"general": {
3+
"push_client_mods": false,
4+
"sync_mode": 2
5+
},
6+
"connection": {
7+
"port": 38067,
8+
"buffer": 65536
9+
},
10+
"rules": {
11+
"directories": [
12+
{
13+
"path": "test-mirror",
14+
"mode": "mirror"
15+
},
16+
{
17+
"path": "test-push",
18+
"mode": "push"
19+
},
20+
"test-default"
21+
],
22+
"files": {
23+
"include": [],
24+
"ignore": [
25+
{
26+
"description": "No jar files allowed",
27+
"pattern": "**/*.jar"
28+
},
29+
{
30+
"pattern": "**/other.bing"
31+
},
32+
"**/basic.thing"
33+
],
34+
"redirect": [
35+
{
36+
"pattern": "**/*.jar",
37+
"redirectTo": "redirected-files"
38+
}
39+
]
40+
}
41+
},
42+
"misc": {
43+
"locale": "en"
44+
}
45+
}

0 commit comments

Comments
 (0)