mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Restrict SpringVersion.getVersion() to "major.minor.patch" format
Closes gh-36785
This commit is contained in:
@@ -38,13 +38,27 @@ 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()
|
||||
*/
|
||||
public static @Nullable 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user