Skip to content

[Detail Bug] EtaInput builds invalid destinations parameter and allows conflicting arrival/departure dates #53

@detail-app

Description

@detail-app

Detail Bug Report

https://app.detail.dev/org_befd6425-a158-4e24-9d4d-1e5c08769515/bugs/bug_d28a6209-55ca-4e7e-868c-5a78ca5d13ac

Summary

  • Context: EtaInput is a record that holds input parameters for the Apple Maps Server API /v1/etas endpoint, which calculates travel time estimates from an origin to multiple destinations.
  • Bug: The DESTINATION_SEPARATOR is incorrectly defined as a pipe (|) instead of a comma (,), and the class fails to validate that arrivalDate and departureDate are 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 both arrivalDate and departureDate to 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/etas documentation specifies that destinations must 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." EtaInput emits 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/departureDate during 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 🟢
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions