From 57b62dd73ae1088581fe35d179ae82f2e55795a3 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 12 May 2026 16:20:47 +0200 Subject: [PATCH] Restrict SpringVersion.getVersion() to "major.minor.patch" format Closes gh-36785 (cherry picked from commit c048074436372867fdf653846eab57211669039b) --- .../springframework/core/SpringVersion.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/SpringVersion.java b/spring-core/src/main/java/org/springframework/core/SpringVersion.java index 3252ea762d1..3f85460510e 100644 --- a/spring-core/src/main/java/org/springframework/core/SpringVersion.java +++ b/spring-core/src/main/java/org/springframework/core/SpringVersion.java @@ -38,14 +38,28 @@ public final class SpringVersion { /** - * Return the full version string of the present Spring codebase, + * Return the "major.minor.patch" version string of the present Spring codebase, * or {@code null} if it cannot be determined. * @see Package#getImplementationVersion() */ @Nullable public static String getVersion() { Package pkg = SpringVersion.class.getPackage(); - return (pkg != null ? pkg.getImplementationVersion() : null); + String version = (pkg != null ? pkg.getImplementationVersion() : null); + if (version != null) { + int idx = version.indexOf('.'); // after major + if (idx != -1) { + idx = version.indexOf('.', idx + 1); // after minor + if (idx != -1) { + idx = version.indexOf('.', idx + 1); // after patch + if (idx != -1) { + // Ignore anything beyond "major.minor.patch" + version = version.substring(0, idx); + } + } + } + } + return version; } }