diff options
| -rw-r--r-- | main/src/cgeo/geocaching/cgData.java | 8 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/cgDataTest.java | 31 |
2 files changed, 36 insertions, 3 deletions
diff --git a/main/src/cgeo/geocaching/cgData.java b/main/src/cgeo/geocaching/cgData.java index 62e6664..f7b52e0 100644 --- a/main/src/cgeo/geocaching/cgData.java +++ b/main/src/cgeo/geocaching/cgData.java @@ -2743,8 +2743,6 @@ public class cgData { /** * checks if this is a newly created database - * - * @return */ public static boolean isNewlyCreatedDatebase() { return newlyCreatedDatabase; @@ -2757,6 +2755,10 @@ public class cgData { newlyCreatedDatabase = false; } + /** + * Creates the WHERE clause for matching multiple geocodes. This automatically converts all given codes to + * UPPERCASE. + */ private static StringBuilder whereGeocodeIn(Set<String> geocodes) { final StringBuilder where = new StringBuilder(); @@ -2766,7 +2768,7 @@ public class cgData { if (all.length() > 0) { all.append(','); } - all.append(DatabaseUtils.sqlEscapeString(geocode)); + all.append(DatabaseUtils.sqlEscapeString(StringUtils.upperCase(geocode))); } where.append("geocode in (").append(all).append(')'); diff --git a/tests/src/cgeo/geocaching/cgDataTest.java b/tests/src/cgeo/geocaching/cgDataTest.java index c82053e..cacf061 100644 --- a/tests/src/cgeo/geocaching/cgDataTest.java +++ b/tests/src/cgeo/geocaching/cgDataTest.java @@ -9,6 +9,8 @@ import cgeo.geocaching.enumerations.LoadFlags.SaveFlag; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.geopoint.Viewport; +import org.apache.commons.lang3.StringUtils; + import java.util.ArrayList; import java.util.Collections; import java.util.EnumSet; @@ -125,6 +127,35 @@ public class cgDataTest extends CGeoTestCase { } } + // Check that loading a cache by case insensitive geo code works correctly (see #3139) + public static void testGeocodeCaseInsensitive() { + + final String GEOCODE_CACHE = "TEST"; + final String upperCase = GEOCODE_CACHE; + final String lowerCase = StringUtils.lowerCase(upperCase); + assertFalse(upperCase.equals(lowerCase)); + + // create cache and trackable + final Geocache cache = new Geocache(); + cache.setGeocode(upperCase); + cache.setDetailed(true); + + try { + final Geocache oldCache = cgData.loadCache(upperCase, LoadFlags.LOAD_ALL_DB_ONLY); + assertNull("Database contained old cache!", oldCache); + + cgData.saveCache(cache, EnumSet.of(SaveFlag.SAVE_DB)); + final Geocache cacheWithOriginalCode = cgData.loadCache(upperCase, LoadFlags.LOAD_ALL_DB_ONLY); + assertNotNull("Cache was not saved correctly!", cacheWithOriginalCode); + + final Geocache cacheLowerCase = cgData.loadCache(lowerCase, LoadFlags.LOAD_ALL_DB_ONLY); + assertNotNull("Could not find cache by case insensitive geocode", cacheLowerCase); + + } finally { + cgData.removeCache(upperCase, LoadFlags.REMOVE_ALL); + } + } + // Loading logs for an empty geocode should return an empty list, not null! public static void testLoadLogsFromEmptyGeocode() { |
