From ab0a255fc821fe48e8b16569a1e74a0bbf1a2228 Mon Sep 17 00:00:00 2001 From: "David M. Lloyd" Date: Fri, 22 Nov 2019 10:39:07 -0600 Subject: [PATCH] Add consistent trimming behavior to converters --- .../quarkus/runtime/configuration/CidrAddressConverter.java | 3 ++- .../io/quarkus/runtime/configuration/DurationConverter.java | 1 + .../runtime/configuration/HyphenateEnumConverter.java | 5 ++--- .../quarkus/runtime/configuration/InetAddressConverter.java | 3 ++- .../runtime/configuration/InetSocketAddressConverter.java | 3 ++- .../quarkus/runtime/configuration/MemorySizeConverter.java | 1 + 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/core/runtime/src/main/java/io/quarkus/runtime/configuration/CidrAddressConverter.java b/core/runtime/src/main/java/io/quarkus/runtime/configuration/CidrAddressConverter.java index b99781b8f35fc..708693b26cccb 100644 --- a/core/runtime/src/main/java/io/quarkus/runtime/configuration/CidrAddressConverter.java +++ b/core/runtime/src/main/java/io/quarkus/runtime/configuration/CidrAddressConverter.java @@ -15,7 +15,8 @@ public class CidrAddressConverter implements Converter { @Override - public CidrAddress convert(final String value) { + public CidrAddress convert(String value) { + value = value.trim(); if (value.isEmpty()) { return null; } diff --git a/core/runtime/src/main/java/io/quarkus/runtime/configuration/DurationConverter.java b/core/runtime/src/main/java/io/quarkus/runtime/configuration/DurationConverter.java index 3746e210cf0d1..6e1406aedc601 100644 --- a/core/runtime/src/main/java/io/quarkus/runtime/configuration/DurationConverter.java +++ b/core/runtime/src/main/java/io/quarkus/runtime/configuration/DurationConverter.java @@ -32,6 +32,7 @@ public DurationConverter() { */ @Override public Duration convert(String value) { + value = value.trim(); if (value.isEmpty()) { return null; } diff --git a/core/runtime/src/main/java/io/quarkus/runtime/configuration/HyphenateEnumConverter.java b/core/runtime/src/main/java/io/quarkus/runtime/configuration/HyphenateEnumConverter.java index 45d88f8db3747..20032f9b714f6 100644 --- a/core/runtime/src/main/java/io/quarkus/runtime/configuration/HyphenateEnumConverter.java +++ b/core/runtime/src/main/java/io/quarkus/runtime/configuration/HyphenateEnumConverter.java @@ -35,11 +35,10 @@ public static > HyphenateEnumConverter of(Class enumType @Override public E convert(String value) { - if (value == null || value.trim().isEmpty()) { + value = value.trim(); + if (value.isEmpty()) { return null; } - - value = value.trim(); final String hyphenatedValue = hyphenate(value); final Enum enumValue = values.get(hyphenatedValue); diff --git a/core/runtime/src/main/java/io/quarkus/runtime/configuration/InetAddressConverter.java b/core/runtime/src/main/java/io/quarkus/runtime/configuration/InetAddressConverter.java index 94c5c498df6ab..b7adf02c8ad6e 100644 --- a/core/runtime/src/main/java/io/quarkus/runtime/configuration/InetAddressConverter.java +++ b/core/runtime/src/main/java/io/quarkus/runtime/configuration/InetAddressConverter.java @@ -17,7 +17,8 @@ public class InetAddressConverter implements Converter { @Override - public InetAddress convert(final String value) { + public InetAddress convert(String value) { + value = value.trim(); if (value.isEmpty()) { return null; } diff --git a/core/runtime/src/main/java/io/quarkus/runtime/configuration/InetSocketAddressConverter.java b/core/runtime/src/main/java/io/quarkus/runtime/configuration/InetSocketAddressConverter.java index 42fa13083715d..ed3a3785e3512 100644 --- a/core/runtime/src/main/java/io/quarkus/runtime/configuration/InetSocketAddressConverter.java +++ b/core/runtime/src/main/java/io/quarkus/runtime/configuration/InetSocketAddressConverter.java @@ -19,7 +19,8 @@ public class InetSocketAddressConverter implements Converter { @Override - public InetSocketAddress convert(final String value) { + public InetSocketAddress convert(String value) { + value = value.trim(); if (value.isEmpty()) { return null; } diff --git a/core/runtime/src/main/java/io/quarkus/runtime/configuration/MemorySizeConverter.java b/core/runtime/src/main/java/io/quarkus/runtime/configuration/MemorySizeConverter.java index fbe8e5f95e331..e4361653cfc75 100644 --- a/core/runtime/src/main/java/io/quarkus/runtime/configuration/MemorySizeConverter.java +++ b/core/runtime/src/main/java/io/quarkus/runtime/configuration/MemorySizeConverter.java @@ -42,6 +42,7 @@ public class MemorySizeConverter implements Converter { * @return {@link MemorySize} - a memory size represented by the given value */ public MemorySize convert(String value) { + value = value.trim(); if (value.isEmpty()) { return null; }