From e52c8b810eefc1f41de4d82e53c40720eab173af Mon Sep 17 00:00:00 2001 From: Taylor Smock Date: Wed, 24 May 2023 06:31:38 -0600 Subject: [PATCH] Fix #22963: URL encoding errors when http2 is enabled Signed-off-by: Taylor Smock --- .../spi/preferences/IMapillaryUrls.java | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapillary/spi/preferences/IMapillaryUrls.java b/src/main/java/org/openstreetmap/josm/plugins/mapillary/spi/preferences/IMapillaryUrls.java index 1986f179f..d21506f41 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapillary/spi/preferences/IMapillaryUrls.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapillary/spi/preferences/IMapillaryUrls.java @@ -63,6 +63,25 @@ public interface IMapillaryUrls { */ String getAccessId(); + /** + * Get the access id in a URL safe manner (the http2 plugin doesn't like {@code "|"} characters) + * + * @return The access id + */ + default String getUrlEncodedAccessId() { + final String originalAccessId = getAccessId(); + if (originalAccessId == null) { + return null; + } + try { + // Once we move to Java 10+, we can drop the name() and the catch + return URLEncoder.encode(originalAccessId, StandardCharsets.UTF_8.name()); + } catch (UnsupportedEncodingException unsupportedEncodingException) { + // We've hardcoded the UTF-8 charset, so this should never happen unless Java drops UTF_8. + throw new JosmRuntimeException(unsupportedEncodingException); + } + } + /** * Get the client id * @@ -91,7 +110,7 @@ public interface IMapillaryUrls { */ default String getTrafficSigns() { return MapillaryConfig.getUrls().getBaseTileUrl() + "mly_map_feature_traffic_sign/2/{z}/{x}/{y}?access_token=" - + getAccessId(); + + getUrlEncodedAccessId(); } /** @@ -101,7 +120,7 @@ default String getTrafficSigns() { */ default String getObjectDetections() { return MapillaryConfig.getUrls().getBaseTileUrl() + "mly_map_feature_point/2/{z}/{x}/{y}?access_token=" - + getAccessId(); + + getUrlEncodedAccessId(); } /** @@ -124,9 +143,10 @@ default String getDetectionInformation(long image) { default String getImages() { if (Boolean.TRUE.equals(MapillaryProperties.USE_COMPUTED_LOCATIONS.get())) { return MapillaryConfig.getUrls().getBaseTileUrl() + "mly1_computed_public/2/{z}/{x}/{y}?access_token=" - + getAccessId(); + + getUrlEncodedAccessId(); } - return MapillaryConfig.getUrls().getBaseTileUrl() + "mly1_public/2/{z}/{x}/{y}?access_token=" + getAccessId(); + return MapillaryConfig.getUrls().getBaseTileUrl() + "mly1_public/2/{z}/{x}/{y}?access_token=" + + getUrlEncodedAccessId(); } /**