From 6b7c24c762f3bf03f5efc8e114621d04a5ff889a Mon Sep 17 00:00:00 2001 From: bardrop Date: Tue, 24 Nov 2026 12:13:05 +0530 Subject: [PATCH] fix: format query locations independently of the default locale --- CHANGELOG.md | 1 + .../contentful/java/cda/QueryOperation.java | 6 ++++-- .../com/contentful/java/cda/AbsQueryTest.java | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f2e03bd..e68a4fdf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased Merged to `master` after 10.6.1 and not yet released. Because Retrofit changes major version, release this as **10.7.0**: - fix: Android apps no longer get `Duplicate class okhttp3.…` build errors (`okhttp-jvm` next to `okhttp-android`), and no exclusion is needed. The SDK now publishes Gradle module metadata that leaves out `okhttp-jvm`, so Gradle picks the right OkHttp artifact per platform. The POM is unchanged, so Maven users are unaffected +- fix: `Location`, `BoundingBox` and `BoundingCircle` queries no longer depend on the default locale (`52,500000,13,400000` on a German device) - chore(deps): OkHttp pinned to **5.3.2**: `okhttp-android` 5.4+ would force Android apps to compileSdk 36/37 - chore(deps): Retrofit **3.0.0** (#371; binary-compatible with 2.11 for `retrofit`, `converter-gson`, `adapter-rxjava3`), Gson 2.14.0 (#359), named-regexp 1.x (#370) - chore(deps): build and test tooling updates (Truth 1.4.5, checkstyle, Maven plugins) diff --git a/src/main/java/com/contentful/java/cda/QueryOperation.java b/src/main/java/com/contentful/java/cda/QueryOperation.java index 6350ead6..987dd043 100644 --- a/src/main/java/com/contentful/java/cda/QueryOperation.java +++ b/src/main/java/com/contentful/java/cda/QueryOperation.java @@ -1,5 +1,7 @@ package com.contentful.java.cda; +import java.util.Locale; + /** * This enumeration will be used to formulate more complex search queries. * @@ -92,7 +94,7 @@ public Location(double latitude, double longitude) { */ @Override public String toString() { - return String.format("%f,%f", latitude, longitude); + return String.format(Locale.ROOT, "%f,%f", latitude, longitude); } } @@ -169,7 +171,7 @@ public BoundingCircle(double centerLatitude, double centerLongitude, double radi * @return returns a url friendly representation. */ @Override public String toString() { - return String.format("%s,%f", center.toString(), radius); + return String.format(Locale.ROOT, "%s,%f", center.toString(), radius); } } } diff --git a/src/test/java/com/contentful/java/cda/AbsQueryTest.java b/src/test/java/com/contentful/java/cda/AbsQueryTest.java index 10a7778b..1ce93752 100644 --- a/src/test/java/com/contentful/java/cda/AbsQueryTest.java +++ b/src/test/java/com/contentful/java/cda/AbsQueryTest.java @@ -10,6 +10,8 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; +import java.util.Locale; + import static com.contentful.java.cda.QueryOperation.Exists; import static com.contentful.java.cda.QueryOperation.HasAllOf; import static com.contentful.java.cda.QueryOperation.HasNoneOf; @@ -467,6 +469,22 @@ public void nearThrowsIfNotUsedWithContentType() { query.where("fields.bar", IsCloseTo, new Location(52, 14)); } + @Test + public void locationsDoNotDependOnTheDefaultLocale() { + final Locale defaultLocale = Locale.getDefault(); + try { + Locale.setDefault(Locale.GERMANY); + + assertThat(new Location(52.5, 13.4).toString()).isEqualTo("52.500000,13.400000"); + assertThat(new BoundingBox(1.5, 2.5, 3.5, 4.5).toString()) + .isEqualTo("1.500000,2.500000,3.500000,4.500000"); + assertThat(new BoundingCircle(new Location(52.5, 13.4), 0.5).toString()) + .isEqualTo("52.500000,13.400000,0.500000"); + } finally { + Locale.setDefault(defaultLocale); + } + } + @Test public void withinBoundingBox() { query.withContentType("foo");