-
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:
EtaInputis a record that holds input parameters for the Apple Maps Server API/v1/etasendpoint, which calculates travel time estimates from an origin to multiple destinations. - Bug: The
DESTINATION_SEPARATORis incorrectly defined as a pipe (|) instead of a comma (,), and the class fails to validate thatarrivalDateanddepartureDateare not both specified simultaneously. - Actual vs. expected: The code joins multiple destinations using a pipe character and encodes it as
%7C, whereas the Apple Maps Server API expects a comma-separated list of coordinate pairs. Additionally, it allows botharrivalDateanddepartureDateto be present in the query string, which is prohibited by the API. - Impact: Requests with multiple destinations will fail with a 400 Bad Request error because the API cannot parse the pipe-separated coordinates. Similarly, providing both arrival and departure dates will lead to API errors.
Code with bug
00025| private static final String DESTINATION_SEPARATOR = "|"; // <-- BUG 🔴 Should be ","
...
00055| public String toQueryString() {
00056| List<String> parameters = new ArrayList<>();
00057| parameters.add(formatParameter(PARAMETER_ORIGIN, encode(origin.toQueryString())));
00058| parameters.add(formatParameter(PARAMETER_DESTINATIONS, encode(joinDestinations(destinations))));
00059| transportType.ifPresent(transportMode -> parameters.add(formatParameter(PARAMETER_TRANSPORT_TYPE, transportMode.apiValue())));
00060| departureDate.ifPresent(departureDateText -> parameters.add(formatParameter(PARAMETER_DEPARTURE_DATE, encode(departureDateText))));
00061| arrivalDate.ifPresent(arrivalDateText -> parameters.add(formatParameter(PARAMETER_ARRIVAL_DATE, encode(arrivalDateText))));
00062| return QUERY_PREFIX + String.join(PARAMETER_SEPARATOR, parameters); // <-- BUG 🔴 Missing validation: specify either departureDate or arrivalDate, but not both
00063| }API specification discrepancy
- The Apple Maps Server API
/v1/etasdocumentation specifies thatdestinationsmust be a "comma-separated list of destination coordinate pairs". Using a pipe (|, encoded as%7C) produces an invalid query value the API cannot parse, resulting in 400 Bad Request for multi-destination requests. - The API contract also states: "Specify either arrivalDate or departureDate, but not both."
EtaInputemits both when provided, violating the contract and triggering API errors.
Recommended fix
- Change the destination separator to a comma and enforce mutual exclusivity of
arrivalDate/departureDateduring construction.
private static final String DESTINATION_SEPARATOR = ","; // <-- FIX 🟢
public EtaInput {
origin = Objects.requireNonNull(origin, "origin");
destinations = normalizeList(destinations);
transportType = normalizeOptional(transportType);
departureDate = normalizeOptional(departureDate);
arrivalDate = normalizeOptional(arrivalDate);
validateDestinations(destinations);
validateDates(arrivalDate, departureDate); // <-- FIX 🟢
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working