Skip to content

Commit e52c8b8

Browse files
committed
Fix #22963: URL encoding errors when http2 is enabled
Signed-off-by: Taylor Smock <tsmock@meta.com>
1 parent 1138a62 commit e52c8b8

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/main/java/org/openstreetmap/josm/plugins/mapillary/spi/preferences/IMapillaryUrls.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,25 @@ public interface IMapillaryUrls {
6363
*/
6464
String getAccessId();
6565

66+
/**
67+
* Get the access id in a URL safe manner (the http2 plugin doesn't like {@code "|"} characters)
68+
*
69+
* @return The access id
70+
*/
71+
default String getUrlEncodedAccessId() {
72+
final String originalAccessId = getAccessId();
73+
if (originalAccessId == null) {
74+
return null;
75+
}
76+
try {
77+
// Once we move to Java 10+, we can drop the name() and the catch
78+
return URLEncoder.encode(originalAccessId, StandardCharsets.UTF_8.name());
79+
} catch (UnsupportedEncodingException unsupportedEncodingException) {
80+
// We've hardcoded the UTF-8 charset, so this should never happen unless Java drops UTF_8.
81+
throw new JosmRuntimeException(unsupportedEncodingException);
82+
}
83+
}
84+
6685
/**
6786
* Get the client id
6887
*
@@ -91,7 +110,7 @@ public interface IMapillaryUrls {
91110
*/
92111
default String getTrafficSigns() {
93112
return MapillaryConfig.getUrls().getBaseTileUrl() + "mly_map_feature_traffic_sign/2/{z}/{x}/{y}?access_token="
94-
+ getAccessId();
113+
+ getUrlEncodedAccessId();
95114
}
96115

97116
/**
@@ -101,7 +120,7 @@ default String getTrafficSigns() {
101120
*/
102121
default String getObjectDetections() {
103122
return MapillaryConfig.getUrls().getBaseTileUrl() + "mly_map_feature_point/2/{z}/{x}/{y}?access_token="
104-
+ getAccessId();
123+
+ getUrlEncodedAccessId();
105124
}
106125

107126
/**
@@ -124,9 +143,10 @@ default String getDetectionInformation(long image) {
124143
default String getImages() {
125144
if (Boolean.TRUE.equals(MapillaryProperties.USE_COMPUTED_LOCATIONS.get())) {
126145
return MapillaryConfig.getUrls().getBaseTileUrl() + "mly1_computed_public/2/{z}/{x}/{y}?access_token="
127-
+ getAccessId();
146+
+ getUrlEncodedAccessId();
128147
}
129-
return MapillaryConfig.getUrls().getBaseTileUrl() + "mly1_public/2/{z}/{x}/{y}?access_token=" + getAccessId();
148+
return MapillaryConfig.getUrls().getBaseTileUrl() + "mly1_public/2/{z}/{x}/{y}?access_token="
149+
+ getUrlEncodedAccessId();
130150
}
131151

132152
/**

0 commit comments

Comments
 (0)