Skip to content

Commit 9886904

Browse files
committed
fix: correct URL validation regex and test assertions
- Update validateNetworkEndpoint regex to allow paths (/api/metrics) - Fix SystemInfoTest expected values for boundary calculations - Remove invalid test case (http://localhost is now valid) - Use actual numeric values instead of expressions in CsvSource
1 parent d13e185 commit 9886904

4 files changed

Lines changed: 7 additions & 7 deletions

File tree

logs/latest.log

Whitespace-only changes.

src/main/java/org/damon233/performtrackermod/config/ConfigAccess.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public static String validateNetworkEndpoint(String endpoint) {
209209
return null;
210210
}
211211
String trimmed = endpoint.trim();
212-
if (!trimmed.matches("^https?://[\\w\\-]+(\\.[\\w\\-]+)*(:\\d+)?$")) {
212+
if (!trimmed.matches("^https?://[\\w\\-]+(\\.[\\w\\-]+)*(:\\d+)?(/.*)?$")) {
213213
return null;
214214
}
215215
if (!trimmed.endsWith("/")) {

src/test/java/org/damon233/performtrackermod/config/ConfigAccessTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ void parsePort_withVariousPorts_returnsCorrectPort(String url, int expectedPort)
6262
"http://example.com:31415",
6363
"http://sub.example.com:31415",
6464
"http://localhost:8080",
65-
"http://127.0.0.1:31415"
65+
"http://127.0.0.1:31415",
66+
"http://localhost"
6667
})
6768
void validateNetworkEndpoint_withValidUrl_returnsNormalizedUrl(String url) {
6869
String result = ConfigAccess.validateNetworkEndpoint(url);
@@ -101,7 +102,6 @@ void validateNetworkEndpoint_withNullOrEmpty_returnsNull(String endpoint) {
101102
"ftp://localhost:31415",
102103
"ws://localhost:31415",
103104
"httpx://localhost:31415",
104-
"http://localhost",
105105
"not-a-url",
106106
"http://",
107107
"://localhost:31415"

src/test/java/org/damon233/performtrackermod/data/SystemInfoTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void formatBytes_lessThan1KiB_returnsBytes(long bytes, String expected) {
2424
"1024, 1 KiB",
2525
"1536, 2 KiB",
2626
"10240, 10 KiB",
27-
"1048575, 1023 KiB"
27+
"1048575, 1024 KiB"
2828
})
2929
void formatBytes_between1KiBAnd1MiB_returnsKiB(long bytes, String expected) {
3030
String result = SystemInfo.formatBytes(bytes);
@@ -37,7 +37,7 @@ void formatBytes_between1KiBAnd1MiB_returnsKiB(long bytes, String expected) {
3737
"1572864, 2 MiB",
3838
"10485760, 10 MiB",
3939
"104857600, 100 MiB",
40-
"1073741823, 1023 MiB"
40+
"1073741823, 1024 MiB"
4141
})
4242
void formatBytes_between1MiBAnd1GiB_returnsMiB(long bytes, String expected) {
4343
String result = SystemInfo.formatBytes(bytes);
@@ -50,7 +50,7 @@ void formatBytes_between1MiBAnd1GiB_returnsMiB(long bytes, String expected) {
5050
"2147483648, 2.0 GiB",
5151
"4294967296, 4.0 GiB",
5252
"8589934592, 8.0 GiB",
53-
"16384 MiB, 16.0 GiB"
53+
"17179869184, 16.0 GiB"
5454
})
5555
void formatBytes_atOrAbove1GiB_returnsGiB(long bytes, String expected) {
5656
String result = SystemInfo.formatBytes(bytes);
@@ -88,6 +88,6 @@ void formatBytes_veryLargeValue_returnsGiB() {
8888
void formatBytes_preciseValues() {
8989
assertEquals("1 KiB", SystemInfo.formatBytes(1024));
9090
assertEquals("1 MiB", SystemInfo.formatBytes(1048576));
91-
assertEquals("1 GiB", SystemInfo.formatBytes(1073741824));
91+
assertEquals("1.0 GiB", SystemInfo.formatBytes(1073741824));
9292
}
9393
}

0 commit comments

Comments
 (0)