diff --git a/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java b/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java index d7067d8a6a..f1ae2a43fe 100644 --- a/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java +++ b/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 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. @@ -705,8 +705,8 @@ public class AntPathMatcher implements PathMatcher { else { this.exactMatch = false; patternBuilder.append(quote(pattern, end, pattern.length())); - this.pattern = (this.caseSensitive ? Pattern.compile(patternBuilder.toString()) : - Pattern.compile(patternBuilder.toString(), Pattern.CASE_INSENSITIVE)); + this.pattern = Pattern.compile(patternBuilder.toString(), + Pattern.DOTALL | (this.caseSensitive ? 0 : Pattern.CASE_INSENSITIVE)); } } diff --git a/spring-core/src/test/java/org/springframework/util/AntPathMatcherTests.java b/spring-core/src/test/java/org/springframework/util/AntPathMatcherTests.java index b018e99caf..71eb80a23f 100644 --- a/spring-core/src/test/java/org/springframework/util/AntPathMatcherTests.java +++ b/spring-core/src/test/java/org/springframework/util/AntPathMatcherTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 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. @@ -131,6 +131,7 @@ class AntPathMatcherTests { assertThat(pathMatcher.match("/{bla}.*", "/testing.html")).isTrue(); assertThat(pathMatcher.match("/{bla}", "//x\ny")).isTrue(); + assertThat(pathMatcher.match("/{var:.*}", "/x\ny")).isTrue(); } @Test diff --git a/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java b/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java index 4581158f85..d854c40e92 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java +++ b/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java @@ -520,7 +520,7 @@ public class Jackson2ObjectMapperBuilder { } /** - * Specify one or more modules to be registered with the {@link ObjectMapper}. + * Specify the modules to be registered with the {@link ObjectMapper}. *
Multiple invocations are not additive, the last one defines the modules to * register. *
Note: If this is set, no finding of modules is going to happen - not by @@ -537,15 +537,9 @@ public class Jackson2ObjectMapperBuilder { } /** - * Set a complete list of modules to be registered with the {@link ObjectMapper}. - *
Multiple invocations are not additive, the last one defines the modules to - * register. - *
Note: If this is set, no finding of modules is going to happen - not by - * Jackson, and not by Spring either (see {@link #findModulesViaServiceLoader}). - * As a consequence, specifying an empty list here will suppress any kind of - * module detection. - *
Specify either this or {@link #modulesToInstall}, not both.
+ * Variant of {@link #modules(Module...)} with a {@link List}.
* @see #modules(Module...)
+ * @see #modules(Consumer)
* @see com.fasterxml.jackson.databind.Module
*/
public Jackson2ObjectMapperBuilder modules(List Multiple invocations are not additive, the last one defines the modules
@@ -565,6 +575,7 @@ public class Jackson2ObjectMapperBuilder {
* allowing to eventually override their configuration.
* Specify either this or {@link #modules(Module...)}, not both.
* @since 4.1.5
+ * @see #modulesToInstall(Consumer)
* @see #modulesToInstall(Class...)
* @see com.fasterxml.jackson.databind.Module
*/
@@ -574,6 +585,21 @@ public class Jackson2ObjectMapperBuilder {
return this;
}
+ /**
+ * Variant of {@link #modulesToInstall(Module...)} with a {@link Consumer}
+ * for full control over the underlying list of modules.
+ * @since 6.0
+ * @see #modulesToInstall(Module...)
+ * @see #modulesToInstall(Class...)
+ * @see com.fasterxml.jackson.databind.Module
+ */
+ public Jackson2ObjectMapperBuilder modulesToInstall(Consumer Specify either this or {@link #modules(Module...)}, not both.
* @see #modulesToInstall(Module...)
+ * @see #modulesToInstall(Consumer)
* @see com.fasterxml.jackson.databind.Module
*/
@SafeVarargs
diff --git a/spring-web/src/main/java/org/springframework/web/util/pattern/CaptureVariablePathElement.java b/spring-web/src/main/java/org/springframework/web/util/pattern/CaptureVariablePathElement.java
index 856c35af98..b3002295a9 100644
--- a/spring-web/src/main/java/org/springframework/web/util/pattern/CaptureVariablePathElement.java
+++ b/spring-web/src/main/java/org/springframework/web/util/pattern/CaptureVariablePathElement.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2021 the original author or authors.
+ * Copyright 2002-2022 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.
@@ -59,15 +59,9 @@ class CaptureVariablePathElement extends PathElement {
}
else {
this.variableName = new String(captureDescriptor, 1, colon - 1);
- if (caseSensitive) {
- this.constraintPattern = Pattern.compile(
- new String(captureDescriptor, colon + 1, captureDescriptor.length - colon - 2));
- }
- else {
- this.constraintPattern = Pattern.compile(
- new String(captureDescriptor, colon + 1, captureDescriptor.length - colon - 2),
- Pattern.CASE_INSENSITIVE);
- }
+ this.constraintPattern = Pattern.compile(
+ new String(captureDescriptor, colon + 1, captureDescriptor.length - colon - 2),
+ Pattern.DOTALL | (caseSensitive ? 0 : Pattern.CASE_INSENSITIVE));
}
}
diff --git a/spring-web/src/main/java/org/springframework/web/util/pattern/RegexPathElement.java b/spring-web/src/main/java/org/springframework/web/util/pattern/RegexPathElement.java
index c5cd8f588f..d66e7a7ce2 100644
--- a/spring-web/src/main/java/org/springframework/web/util/pattern/RegexPathElement.java
+++ b/spring-web/src/main/java/org/springframework/web/util/pattern/RegexPathElement.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2021 the original author or authors.
+ * Copyright 2002-2022 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.
@@ -108,12 +108,8 @@ class RegexPathElement extends PathElement {
}
patternBuilder.append(quote(text, end, text.length()));
- if (this.caseSensitive) {
- return Pattern.compile(patternBuilder.toString());
- }
- else {
- return Pattern.compile(patternBuilder.toString(), Pattern.CASE_INSENSITIVE);
- }
+ return Pattern.compile(patternBuilder.toString(),
+ Pattern.DOTALL | (this.caseSensitive ? 0 : Pattern.CASE_INSENSITIVE));
}
public List> consumer) {
+ this.modules = (this.modules != null ? this.modules : new ArrayList<>());
+ this.findModulesViaServiceLoader = false;
+ this.findWellKnownModules = false;
+ consumer.accept(this.modules);
+ return this;
+ }
+
/**
* Specify one or more modules to be registered with the {@link ObjectMapper}.
*
> consumer) {
+ this.modules = (this.modules != null ? this.modules : new ArrayList<>());
+ this.findWellKnownModules = true;
+ consumer.accept(this.modules);
+ return this;
+ }
+
/**
* Specify one or more modules by class to be registered with
* the {@link ObjectMapper}.
@@ -585,6 +611,7 @@ public class Jackson2ObjectMapperBuilder {
* allowing to eventually override their configuration.
*