Skip to content

Commit e9320b6

Browse files
committed
Merge branch '3.1.x' into 4.0.x
2 parents 9810538 + 3910fbf commit e9320b6

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/ConfigServerConfigDataResource.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,27 @@ private boolean urisEqual(String[] thatUris) {
123123
}
124124

125125
private boolean uriEqual(String thisUriString, String thatUriString) {
126-
UriComponents thisUri = UriComponentsBuilder.fromHttpUrl(thisUriString).build();
127-
UriComponents thatUri = UriComponentsBuilder.fromHttpUrl(thatUriString).build();
128-
return Objects.equals(thisUri.getHost(), thatUri.getHost())
129-
&& Objects.equals(thisUri.getPort(), thatUri.getPort())
130-
&& Objects.equals(thisUri.getPath(), thatUri.getPath());
126+
try {
127+
UriComponents thisUri = UriComponentsBuilder.fromHttpUrl(thisUriString).build();
128+
UriComponents thatUri = UriComponentsBuilder.fromHttpUrl(thatUriString).build();
129+
return Objects.equals(thisUri.getHost(), thatUri.getHost())
130+
&& Objects.equals(thisUri.getPort(), thatUri.getPort())
131+
&& Objects.equals(thisUri.getPath(), thatUri.getPath());
132+
}
133+
catch (Exception e) {
134+
return Objects.equals(thisUriString, thatUriString);
135+
}
131136
}
132137

133138
private int urisHashCode(String[] uris) {
134139
return Arrays.stream(uris).mapToInt(uriString -> {
135-
UriComponents uriComponents = UriComponentsBuilder.fromHttpUrl(uriString).build();
136-
return Objects.hash(uriComponents.getHost(), uriComponents.getPath(), uriComponents.getPort());
140+
try {
141+
UriComponents uriComponents = UriComponentsBuilder.fromHttpUrl(uriString).build();
142+
return Objects.hash(uriComponents.getHost(), uriComponents.getPath(), uriComponents.getPort());
143+
}
144+
catch (Exception e) {
145+
return Arrays.hashCode(uris);
146+
}
137147
}).sum();
138148
}
139149

spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigServerConfigDataResourceTests.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,4 +318,15 @@ void testEqualsDifferentLabels() {
318318
assertThat(r1.hashCode()).isNotEqualTo(r2.hashCode());
319319
}
320320

321+
@Test
322+
void testInvalidUri() {
323+
ConfigClientProperties r1Properties = new ConfigClientProperties();
324+
r1Properties.setUri(new String[] { "//" });
325+
ConfigServerConfigDataResource r1 = new ConfigServerConfigDataResource(r1Properties, true, null);
326+
ConfigClientProperties r2Properties = new ConfigClientProperties();
327+
r2Properties.setUri(new String[] { "//" });
328+
ConfigServerConfigDataResource r2 = new ConfigServerConfigDataResource(r2Properties, true, null);
329+
assertThat(r1).isEqualTo(r2);
330+
}
331+
321332
}

0 commit comments

Comments
 (0)