mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-05 00:56:58 +08:00
Merge branch '3.2.x'
Closes gh-40869
This commit is contained in:
commit
3858a33162
@ -137,7 +137,7 @@ final class PulsarPropertiesMapper {
|
||||
try {
|
||||
return sortedParams.entrySet()
|
||||
.stream()
|
||||
.map((entry) -> "\"%s\":\"%s\"".formatted(entry.getKey(), entry.getValue()))
|
||||
.map((entry) -> "\"%s\":\"%s\"".formatted(entry.getKey(), escapeJson(entry.getValue())))
|
||||
.collect(Collectors.joining(",", "{", "}"));
|
||||
}
|
||||
catch (Exception ex) {
|
||||
@ -145,6 +145,17 @@ final class PulsarPropertiesMapper {
|
||||
}
|
||||
}
|
||||
|
||||
private String escapeJson(String raw) {
|
||||
return raw.replace("\\", "\\\\")
|
||||
.replace("\"", "\\\"")
|
||||
.replace("/", "\\/")
|
||||
.replace("\b", "\\b")
|
||||
.replace("\t", "\\t")
|
||||
.replace("\n", "\\n")
|
||||
.replace("\f", "\\f")
|
||||
.replace("\r", "\\r");
|
||||
}
|
||||
|
||||
<T> void customizeProducerBuilder(ProducerBuilder<T> producerBuilder) {
|
||||
PulsarProperties.Producer properties = this.properties.getProducer();
|
||||
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
|
||||
|
@ -81,8 +81,10 @@ class PulsarPropertiesMapperTests {
|
||||
@Test
|
||||
void customizeClientBuilderWhenHasAuthentication() throws UnsupportedAuthenticationException {
|
||||
PulsarProperties properties = new PulsarProperties();
|
||||
Map<String, String> params = Map.of("param", "name");
|
||||
String authParamString = "{\"param\":\"name\"}";
|
||||
Map<String, String> params = Map.of("simpleParam", "foo", "complexParam",
|
||||
"{\n\t\"k1\" : \"v1\",\n\t\"k2\":\"v2\"\n}");
|
||||
String authParamString = "{\"complexParam\":\"{\\n\\t\\\"k1\\\" : \\\"v1\\\",\\n\\t\\\"k2\\\":\\\"v2\\\"\\n}\""
|
||||
+ ",\"simpleParam\":\"foo\"}";
|
||||
properties.getClient().getAuthentication().setPluginClassName("myclass");
|
||||
properties.getClient().getAuthentication().setParam(params);
|
||||
ClientBuilder builder = mock(ClientBuilder.class);
|
||||
@ -166,8 +168,10 @@ class PulsarPropertiesMapperTests {
|
||||
@Test
|
||||
void customizeAdminBuilderWhenHasAuthentication() throws UnsupportedAuthenticationException {
|
||||
PulsarProperties properties = new PulsarProperties();
|
||||
Map<String, String> params = Map.of("param", "name");
|
||||
String authParamString = "{\"param\":\"name\"}";
|
||||
Map<String, String> params = Map.of("simpleParam", "foo", "complexParam",
|
||||
"{\n\t\"k1\" : \"v1\",\n\t\"k2\":\"v2\"\n}");
|
||||
String authParamString = "{\"complexParam\":\"{\\n\\t\\\"k1\\\" : \\\"v1\\\",\\n\\t\\\"k2\\\":\\\"v2\\\"\\n}\""
|
||||
+ ",\"simpleParam\":\"foo\"}";
|
||||
properties.getAdmin().getAuthentication().setPluginClassName("myclass");
|
||||
properties.getAdmin().getAuthentication().setParam(params);
|
||||
PulsarAdminBuilder builder = mock(PulsarAdminBuilder.class);
|
||||
|
Loading…
Reference in New Issue
Block a user