From d5a70688cb75be9180c81049f8e1c18c29dd4d15 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 22 Jan 2020 01:07:41 -0800 Subject: [PATCH] Reserve layer names for future use Update layered jar support so that the name `ext` and any name starting `springboot` are reserved. See gh-19767 --- .../org/springframework/boot/loader/tools/Layer.java | 2 ++ .../springframework/boot/loader/tools/LayerTests.java | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Layer.java b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Layer.java index 0de9bba8f0f..0f87ba4eeb5 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Layer.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Layer.java @@ -41,6 +41,8 @@ public class Layer { public Layer(String name) { Assert.hasText(name, "Name must not be empty"); Assert.isTrue(PATTERN.matcher(name).matches(), "Malformed layer name '" + name + "'"); + Assert.isTrue(!name.equalsIgnoreCase("ext") && !name.toLowerCase().startsWith("springboot"), + "Layer name '" + name + "' is reserved"); this.name = name; } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/LayerTests.java b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/LayerTests.java index 7be8b8b9847..2dddf91b6c6 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/LayerTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/LayerTests.java @@ -59,4 +59,14 @@ class LayerTests { assertThat(new Layer("test")).hasToString("test"); } + @Test + void createWhenUsingReservedNameThrowsException() { + assertThatIllegalArgumentException().isThrownBy(() -> new Layer("ext")) + .withMessage("Layer name 'ext' is reserved"); + assertThatIllegalArgumentException().isThrownBy(() -> new Layer("ExT")) + .withMessage("Layer name 'ExT' is reserved"); + assertThatIllegalArgumentException().isThrownBy(() -> new Layer("springbootloader")) + .withMessage("Layer name 'springbootloader' is reserved"); + } + }