diff --git a/spring-boot/src/main/java/org/springframework/boot/bind/RelaxedNames.java b/spring-boot/src/main/java/org/springframework/boot/bind/RelaxedNames.java index 3e335e335e..819943dabe 100644 --- a/spring-boot/src/main/java/org/springframework/boot/bind/RelaxedNames.java +++ b/spring-boot/src/main/java/org/springframework/boot/bind/RelaxedNames.java @@ -200,23 +200,29 @@ public final class RelaxedNames implements Iterable { }; + private static final char[] SUFFIXES = new char[] { '_', '-', '.' }; + public abstract String apply(String value); private static String separatedToCamelCase(String value, boolean caseInsensitive) { + if (value.length() == 0) { + return value; + } StringBuilder builder = new StringBuilder(); for (String field : SEPARATED_TO_CAMEL_CASE_PATTERN.split(value)) { field = (caseInsensitive ? field.toLowerCase() : field); builder.append( builder.length() == 0 ? field : StringUtils.capitalize(field)); } - for (String suffix : new String[] { "_", "-", "." }) { - if (value.endsWith(suffix)) { + char lastChar = value.charAt(value.length() - 1); + for (char suffix : SUFFIXES) { + if (lastChar == suffix) { builder.append(suffix); + break; } } return builder.toString(); - } }