From a86429a62aee956be3097622f4b65a5bcaf2cba7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ey=C3=B0un=20Nielsen?= Date: Wed, 29 Mar 2023 00:17:26 +0100 Subject: [PATCH 1/2] Fix asymmetry of equals when element has trailing dashes See gh-34804 --- .../properties/source/ConfigurationPropertyName.java | 2 +- .../properties/source/ConfigurationPropertyNameTests.java | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java index e7b9eae2e8..a1a3d6b7b1 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java @@ -406,7 +406,7 @@ public final class ConfigurationPropertyName implements Comparable= l2) { - return false; + return remainderIsNotAlphanumeric(e1, i, i1); } char ch1 = e1.charAt(i, i1); char ch2 = e2.charAt(i, i2); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/ConfigurationPropertyNameTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/ConfigurationPropertyNameTests.java index e0afc334b4..2cf37b77a7 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/ConfigurationPropertyNameTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/ConfigurationPropertyNameTests.java @@ -702,6 +702,14 @@ class ConfigurationPropertyNameTests { assertThat(name2).isEqualTo(name1); } + @Test + void equalsSymmetricWhenNameMatchesDueToRemovalOfTrailingDashes() { + ConfigurationPropertyName n1 = ConfigurationPropertyName.of("foobar"); + ConfigurationPropertyName n2 = ConfigurationPropertyName.of("foobar--"); + assertThat(n1).isEqualTo(n2); + assertThat(n2).isEqualTo(n1); + } + @Test void isValidWhenValidShouldReturnTrue() { assertThat(ConfigurationPropertyName.isValid("")).isTrue(); From b06e7e60f9152d0d323884818d8c9a9243310051 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 30 Jun 2023 14:38:31 +0100 Subject: [PATCH 2/2] Polish "Fix asymmetry of equals when element has trailing dashes" See gh-34804 --- .../source/ConfigurationPropertyName.java | 19 +++++++++++++++++-- .../ConfigurationPropertyNameTests.java | 15 +++++++-------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java index a1a3d6b7b1..6713e2f2a1 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -406,7 +406,7 @@ public final class ConfigurationPropertyName implements Comparable= l2) { - return remainderIsNotAlphanumeric(e1, i, i1); + return remainderIsDashes(e1, i, i1); } char ch1 = e1.charAt(i, i1); char ch2 = e2.charAt(i, i2); @@ -487,6 +487,21 @@ public final class ConfigurationPropertyName implements Comparable