Skip to content

Commit 0374f62

Browse files
committed
Fix parsing of coordinate strings when locale is non-English [#628]
1 parent 2697f29 commit 0374f62

3 files changed

Lines changed: 27 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Tiles 4.15.2
2+
------
3+
- Fix parsing of commas in non-English locales [#628]
4+
15
Tiles 4.15.1
26
------
37
- Change to generic Geopackage source for Natural Earth via @mxzinke and @wipfli [#626]

tiles/src/main/java/com/protomaps/basemap/Basemap.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.nio.file.Paths;
2828
import java.util.HashMap;
2929
import java.util.List;
30+
import java.util.Locale;
3031
import java.util.Map;
3132
import org.apache.parquet.ParquetReadOptions;
3233
import org.apache.parquet.hadoop.ParquetFileReader;
@@ -134,7 +135,7 @@ public String description() {
134135

135136
@Override
136137
public String version() {
137-
return "4.15.1";
138+
return "4.15.2";
138139
}
139140

140141
@Override
@@ -179,7 +180,7 @@ static java.util.Optional<String> extractBoundsFromGeoParquet(Path parquetPath)
179180
Envelope bounds = geoparquet.primaryColumnMetadata().envelope();
180181

181182
if (bounds != null && !bounds.isNull() && bounds.getArea() > 0) {
182-
String boundsStr = String.format("%f,%f,%f,%f",
183+
String boundsStr = String.format(Locale.ROOT, "%f,%f,%f,%f",
183184
bounds.getMinX(), bounds.getMinY(), bounds.getMaxX(), bounds.getMaxY());
184185
return java.util.Optional.of(boundsStr);
185186
}

tiles/src/test/java/com/protomaps/basemap/BasemapTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import static org.junit.jupiter.api.Assertions.assertTrue;
66

77
import java.nio.file.Path;
8+
import java.util.Locale;
89
import java.util.Optional;
910
import org.junit.jupiter.api.Test;
1011
import org.junit.jupiter.api.io.TempDir;
@@ -60,6 +61,25 @@ void testExtractBoundsFromValidGeoParquet() {
6061
assertTrue(minY < maxY, "Min Y should be less than Max Y");
6162
}
6263

64+
@Test
65+
void testExtractBoundsUsesRootLocale() {
66+
// A locale with a comma decimal separator must not corrupt the comma-separated bounds string.
67+
Path testFile = Path.of("src", "test", "resources", "test-bounds.parquet");
68+
Locale previous = Locale.getDefault();
69+
try {
70+
Locale.setDefault(Locale.GERMANY);
71+
72+
Optional<String> boundsOpt = Basemap.extractBoundsFromGeoParquet(testFile);
73+
74+
assertTrue(boundsOpt.isPresent(), "Should extract bounds from valid GeoParquet file");
75+
String boundsStr = boundsOpt.get();
76+
assertEquals(4, boundsStr.split(",").length, "Bounds string should have 4 comma-separated values");
77+
assertEquals(-122.4241767, Double.parseDouble(boundsStr.split(",")[0]), 0.0001, "Min X should match");
78+
} finally {
79+
Locale.setDefault(previous);
80+
}
81+
}
82+
6383
@Test
6484
void testExtractBoundsFromNonExistentFile() {
6585
// Test that a non-existent file returns empty

0 commit comments

Comments
 (0)