-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Detail Bug Report
Summary
- Context:
SearchInputgenerates the query string for Apple Maps Search API requests, including location-based hints likesearchLocation,searchRegion, anduserLocation. - Bug: Unlike other input classes (e.g.,
EtaInput),SearchInputfails to URL-encode the values of its location-based parameters intoQueryString(). - Actual vs. expected: Currently, coordinate strings are added raw; they should be URL-encoded to ensure the resulting string is a valid URI, consistent with how
q,language, andpageTokenare handled. - Impact: If a location string contains a space or other special character (allowed by the
SearchLocationconstructor),toQueryString()produces an invalid query string that causesURI.create()to throw anIllegalArgumentException, crashing the request.
Code with bug
searchLocation.ifPresent(value -> parameters.add(formatParameter(PARAMETER_SEARCH_LOCATION, value.toQueryString()))); // <-- BUG 🔴 Missing encode()
searchRegion.ifPresent(value -> parameters.add(formatParameter(PARAMETER_SEARCH_REGION, value.toQueryString())));
userLocation.ifPresent(value -> parameters.add(formatParameter(PARAMETER_USER_LOCATION, value.toQueryString())));Failing test
@Test
void testToQueryStringWithSpaceInLocation() {
SearchInput input = SearchInput.builder("cafe")
.searchLocation(new SearchLocation("37.33, -122.03"))
.build();
String queryString = input.toQueryString();
// queryString contains "searchLocation=37.33, -122.03"
assertThrows(IllegalArgumentException.class, () -> {
URI.create("https://maps-api.apple.com/v1/search" + queryString);
});
}Output: IllegalArgumentException: Illegal character in query at index ... (due to unencoded space in the query string)
Recommended fix
searchLocation.ifPresent(value -> parameters.add(formatParameter(PARAMETER_SEARCH_LOCATION, encode(value.toQueryString())))); // <-- FIX 🟢
searchRegion.ifPresent(value -> parameters.add(formatParameter(PARAMETER_SEARCH_REGION, encode(value.toQueryString()))));
userLocation.ifPresent(value -> parameters.add(formatParameter(PARAMETER_USER_LOCATION, encode(value.toQueryString()))));Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working