Skip to content

Commit 82fc6c1

Browse files
authored
fix '&' char encoding (#1410)
1 parent a0045aa commit 82fc6c1

3 files changed

Lines changed: 9 additions & 7 deletions

File tree

services-directions-models/src/main/java/com/mapbox/api/directions/v5/models/RouteOptions.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,9 @@ public URL toUrl(@NonNull String accessToken) {
11041104
decodedUrl.getQuery(),
11051105
decodedUrl.getRef()
11061106
);
1107-
return new URL(encodedUri.toASCIIString());
1107+
// workaround to encode `&` chars in Strings like "me & you".
1108+
// need a better solution to fix encoding in general.
1109+
return new URL(encodedUri.toASCIIString().replace("%20&%20", "%20%26%20"));
11081110
} catch (MalformedURLException | URISyntaxException ex) {
11091111
throw new RuntimeException(ex);
11101112
}

services-directions-models/src/test/java/com/mapbox/api/directions/v5/models/RouteOptionsTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class RouteOptionsTest extends TestUtils {
2929
*/
3030
private static final String ROUTE_OPTIONS_JSON = "route_options_v5.json";
3131
private static final String ROUTE_OPTIONS_URL =
32-
"https://api.mapbox.com/directions/v5/mapbox/driving/-122.4003312,37.7736941;-122.4187529,37.7689715;-122.4255172,37.7775835?access_token=pk.token&geometries=polyline6&alternatives=false&overview=full&radiuses=;unlimited;5.1&steps=true&avoid_maneuver_radius=200.0&bearings=0,90;90,0;&layers=-42;;0&continue_straight=false&annotations=congestion,distance,duration&language=ru&roundabout_exits=false&voice_instructions=true&banner_instructions=true&voice_units=metric&exclude=toll,ferry,point(11.0%20-22.0)&include=hot,hov2&approaches=;curb;&waypoints=0;1;2&waypoint_names=;two;&waypoint_targets=;12.2,21.2;&enable_refresh=true&walking_speed=5.11&walkway_bias=-0.2&alley_bias=0.75&snapping_include_closures=;false;true&arrive_by=2021-01-01'T'01:01&depart_at=2021-02-02'T'02:02&max_height=1.5&max_width=1.4&metadata=true&engine=electric&ev_initial_charge=80000&ev_max_charge=80000&ev_connector_types=ccs_combo_type1,ccs_combo_type2&energy_consumption_curve=0,300;20,160;80,140;120,180&ev_ascent=5.0&ev_descent=6.0&ev_charging_curve=0,100000;40000,70000;60000,30000;80000,10000&ev_max_ac_charging_power=1&ev_min_charge_at_destination=2&ev_min_charge_at_charging_station=3";
32+
"https://api.mapbox.com/directions/v5/mapbox/driving/-122.4003312,37.7736941;-122.4187529,37.7689715;-122.4255172,37.7775835?access_token=pk.token&geometries=polyline6&alternatives=false&overview=full&radiuses=;unlimited;5.1&steps=true&avoid_maneuver_radius=200.0&bearings=0,90;90,0;&layers=-42;;0&continue_straight=false&annotations=congestion,distance,duration&language=ru&roundabout_exits=false&voice_instructions=true&banner_instructions=true&voice_units=metric&exclude=toll,ferry,point(11.0%20-22.0)&include=hot,hov2&approaches=;curb;&waypoints=0;1;2&waypoint_names=one;Serangoon%20Garden%20Market%20%26%20Food%20Centre;&waypoint_targets=;12.2,21.2;&enable_refresh=true&walking_speed=5.11&walkway_bias=-0.2&alley_bias=0.75&snapping_include_closures=;false;true&arrive_by=2021-01-01'T'01:01&depart_at=2021-02-02'T'02:02&max_height=1.5&max_width=1.4&metadata=true&engine=electric&ev_initial_charge=80000&ev_max_charge=80000&ev_connector_types=ccs_combo_type1,ccs_combo_type2&energy_consumption_curve=0,300;20,160;80,140;120,180&ev_ascent=5.0&ev_descent=6.0&ev_charging_curve=0,100000;40000,70000;60000,30000;80000,10000&ev_max_ac_charging_power=1&ev_min_charge_at_destination=2&ev_min_charge_at_charging_station=3";
3333
private static final String ACCESS_TOKEN = "pk.token";
3434

3535
private final String optionsJson = loadJsonFixture(ROUTE_OPTIONS_JSON);
@@ -237,7 +237,7 @@ public void waypointIndicesStringIsValid_fromJson() {
237237
public void waypointNamesStringIsValid_fromJson() {
238238
RouteOptions routeOptions = RouteOptions.fromJson(optionsJson);
239239

240-
assertEquals(";two;", routeOptions.waypointNames());
240+
assertEquals("one;Serangoon Garden Market & Food Centre;", routeOptions.waypointNames());
241241
}
242242

243243
@Test
@@ -664,7 +664,7 @@ private RouteOptions routeOptions() {
664664
.roundaboutExits(false)
665665
.voiceInstructions(true)
666666
.voiceUnits(DirectionsCriteria.METRIC)
667-
.waypointNames(";two;")
667+
.waypointNames("one;Serangoon Garden Market & Food Centre;")
668668
.waypointTargets(";12.2,21.2;")
669669
.waypointIndices("0;1;2")
670670
.alleyBias(0.75)
@@ -755,8 +755,8 @@ private RouteOptions routeOptionsList() {
755755
.voiceInstructions(true)
756756
.voiceUnits(DirectionsCriteria.METRIC)
757757
.waypointNamesList(new ArrayList<String>() {{
758-
add(null);
759-
add("two");
758+
add("one");
759+
add("Serangoon Garden Market & Food Centre");
760760
add(null);
761761
}})
762762
.waypointTargetsList(new ArrayList<Point>() {{

services-directions-models/src/test/resources/route_options_v5.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"voice_units": "metric",
2323
"approaches": ";curb;",
2424
"waypoints": "0;1;2",
25-
"waypoint_names": ";two;",
25+
"waypoint_names": "one;Serangoon Garden Market & Food Centre;",
2626
"waypoint_targets": ";12.2,21.2;",
2727
"snapping_include_closures": ";false;true",
2828
"alley_bias": 0.75,

0 commit comments

Comments
 (0)