mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Ignore file entries in META-INF/versions of multi-release jar
Fixes gh-41001
This commit is contained in:
parent
d4e9f458a3
commit
217c2c862b
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2023 the original author or authors.
|
* Copyright 2012-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -82,6 +82,7 @@ final class MetaInfVersionsInfo {
|
|||||||
if (contentEntry.hasNameStartingWith(META_INF_VERSIONS) && !contentEntry.isDirectory()) {
|
if (contentEntry.hasNameStartingWith(META_INF_VERSIONS) && !contentEntry.isDirectory()) {
|
||||||
String name = contentEntry.getName();
|
String name = contentEntry.getName();
|
||||||
int slash = name.indexOf('/', META_INF_VERSIONS.length());
|
int slash = name.indexOf('/', META_INF_VERSIONS.length());
|
||||||
|
if (slash > -1) {
|
||||||
String version = name.substring(META_INF_VERSIONS.length(), slash);
|
String version = name.substring(META_INF_VERSIONS.length(), slash);
|
||||||
try {
|
try {
|
||||||
int versionNumber = Integer.parseInt(version);
|
int versionNumber = Integer.parseInt(version);
|
||||||
@ -94,6 +95,7 @@ final class MetaInfVersionsInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return (!versions.isEmpty()) ? new MetaInfVersionsInfo(versions) : NONE;
|
return (!versions.isEmpty()) ? new MetaInfVersionsInfo(versions) : NONE;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2023 the original author or authors.
|
* Copyright 2012-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -72,6 +72,20 @@ class MetaInfVersionsInfoTests {
|
|||||||
assertThat(info).isSameAs(MetaInfVersionsInfo.NONE);
|
assertThat(info).isSameAs(MetaInfVersionsInfo.NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void toleratesUnexpectedFileEntryInMetaInfVersions() {
|
||||||
|
List<ZipContent.Entry> entries = new ArrayList<>();
|
||||||
|
entries.add(mockEntry("META-INF/"));
|
||||||
|
entries.add(mockEntry("META-INF/MANIFEST.MF"));
|
||||||
|
entries.add(mockEntry("META-INF/versions/"));
|
||||||
|
entries.add(mockEntry("META-INF/versions/unexpected"));
|
||||||
|
entries.add(mockEntry("META-INF/versions/9/"));
|
||||||
|
entries.add(mockEntry("META-INF/versions/9/Foo.class"));
|
||||||
|
MetaInfVersionsInfo info = MetaInfVersionsInfo.get(entries.size(), entries::get);
|
||||||
|
assertThat(info.versions()).containsExactly(9);
|
||||||
|
assertThat(info.directories()).containsExactly("META-INF/versions/9/");
|
||||||
|
}
|
||||||
|
|
||||||
private ZipContent.Entry mockEntry(String name) {
|
private ZipContent.Entry mockEntry(String name) {
|
||||||
ZipContent.Entry entry = mock(ZipContent.Entry.class);
|
ZipContent.Entry entry = mock(ZipContent.Entry.class);
|
||||||
given(entry.getName()).willReturn(name);
|
given(entry.getName()).willReturn(name);
|
||||||
|
Loading…
Reference in New Issue
Block a user