Support defaultHtmlEscape in WebFlux

See gh-36400

Signed-off-by: husseinvr97 <husseinmustafabas05@gmail.com>
This commit is contained in:
husseinvr97
2026-02-28 19:42:20 +02:00
committed by rstoyanchev
parent 104a2033c5
commit d4893fb32f
11 changed files with 212 additions and 14 deletions
@@ -49,10 +49,17 @@ public final class MockServerWebExchange extends DefaultServerWebExchange {
MockServerHttpRequest request, @Nullable WebSessionManager sessionManager,
@Nullable ApplicationContext applicationContext, @Nullable Principal principal) {
this(request, sessionManager, applicationContext, null, principal);
}
private MockServerWebExchange(
MockServerHttpRequest request, @Nullable WebSessionManager sessionManager,
@Nullable ApplicationContext applicationContext, @Nullable Boolean defaultHtmlEscape, @Nullable Principal principal) {
super(request, new MockServerHttpResponse(),
sessionManager != null ? sessionManager : new DefaultWebSessionManager(),
ServerCodecConfigurer.create(), new AcceptHeaderLocaleContextResolver(),
applicationContext);
applicationContext, defaultHtmlEscape);
this.principalMono = (principal != null) ? Mono.just(principal) : Mono.empty();
}
@@ -125,6 +132,8 @@ public final class MockServerWebExchange extends DefaultServerWebExchange {
private @Nullable ApplicationContext applicationContext;
private @Nullable Boolean defaultHtmlEscape;
private @Nullable Principal principal;
public Builder(MockServerHttpRequest request) {
@@ -163,6 +172,18 @@ public final class MockServerWebExchange extends DefaultServerWebExchange {
return this;
}
/**
* Set the default HTML escape setting for the exchange.
* @param defaultHtmlEscape whether to enable default HTML escaping,
* or {@code null} if not configured
* @return this builder
* @since 7.0.6
*/
public Builder defaultHtmlEscape(@Nullable Boolean defaultHtmlEscape) {
this.defaultHtmlEscape = defaultHtmlEscape;
return this;
}
/**
* Provide a user to associate with the exchange.
* @param principal the principal to use
@@ -178,7 +199,7 @@ public final class MockServerWebExchange extends DefaultServerWebExchange {
*/
public MockServerWebExchange build() {
return new MockServerWebExchange(
this.request, this.sessionManager, this.applicationContext, this.principal);
this.request, this.sessionManager, this.applicationContext, this.defaultHtmlEscape, this.principal);
}
}