Skip to content

Commit 57b62dd

Browse files
committed
Restrict SpringVersion.getVersion() to "major.minor.patch" format
Closes gh-36785 (cherry picked from commit c048074)
1 parent 5f661f1 commit 57b62dd

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

spring-core/src/main/java/org/springframework/core/SpringVersion.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,28 @@ private SpringVersion() {
3838

3939

4040
/**
41-
* Return the full version string of the present Spring codebase,
41+
* Return the "major.minor.patch" version string of the present Spring codebase,
4242
* or {@code null} if it cannot be determined.
4343
* @see Package#getImplementationVersion()
4444
*/
4545
@Nullable
4646
public static String getVersion() {
4747
Package pkg = SpringVersion.class.getPackage();
48-
return (pkg != null ? pkg.getImplementationVersion() : null);
48+
String version = (pkg != null ? pkg.getImplementationVersion() : null);
49+
if (version != null) {
50+
int idx = version.indexOf('.'); // after major
51+
if (idx != -1) {
52+
idx = version.indexOf('.', idx + 1); // after minor
53+
if (idx != -1) {
54+
idx = version.indexOf('.', idx + 1); // after patch
55+
if (idx != -1) {
56+
// Ignore anything beyond "major.minor.patch"
57+
version = version.substring(0, idx);
58+
}
59+
}
60+
}
61+
}
62+
return version;
4963
}
5064

5165
}

0 commit comments

Comments
 (0)