Polishing and minor refactoring

Update checks whether quoting is needed to be more complete
than what we've used so far, making sure the there is both
opening and closing quotes independent of each other.

See gh-33412
This commit is contained in:
rstoyanchev
2024-09-09 18:19:59 +01:00
parent 80b264ba82
commit 1b26122e64
6 changed files with 69 additions and 33 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -45,7 +45,15 @@ import org.springframework.core.ResolvableType;
import org.springframework.core.io.InputStreamResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.ResourceRegion;
import org.springframework.http.*;
import org.springframework.http.CacheControl;
import org.springframework.http.ETag;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpRange;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.InvalidMediaTypeException;
import org.springframework.http.MediaType;
import org.springframework.http.converter.GenericHttpMessageConverter;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.SmartHttpMessageConverter;
@@ -158,9 +166,9 @@ final class DefaultEntityResponseBuilder<T> implements EntityResponse.Builder<T>
}
@Override
public EntityResponse.Builder<T> eTag(String etag) {
etag = ETag.format(etag);
this.headers.setETag(etag);
public EntityResponse.Builder<T> eTag(String eTag) {
eTag = ETag.quoteETagIfNecessary(eTag);
this.headers.setETag(eTag);
return this;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,7 +30,12 @@ import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.*;
import org.springframework.http.CacheControl;
import org.springframework.http.ETag;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.MediaType;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.LinkedMultiValueMap;
@@ -122,10 +127,10 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder {
}
@Override
public ServerResponse.BodyBuilder eTag(String etag) {
Assert.notNull(etag, "etag must not be null");
etag = ETag.format(etag);
this.headers.setETag(etag);
public ServerResponse.BodyBuilder eTag(String eTag) {
Assert.notNull(eTag, "etag must not be null");
eTag = ETag.quoteETagIfNecessary(eTag);
this.headers.setETag(eTag);
return this;
}