Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
6d9692ff
Commit
6d9692ff
authored
Mar 12, 2018
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix binding to empty prefix when empty name present
Fixes gh-12381
parent
b88e3cb2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
0 deletions
+22
-0
Binder.java
.../springframework/boot/context/properties/bind/Binder.java
+4
-0
BinderTests.java
...ngframework/boot/context/properties/bind/BinderTests.java
+18
-0
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/Binder.java
View file @
6d9692ff
...
...
@@ -46,6 +46,7 @@ import org.springframework.core.env.Environment;
import
org.springframework.format.support.DefaultFormattingConversionService
;
import
org.springframework.util.Assert
;
import
org.springframework.util.ClassUtils
;
import
org.springframework.util.StringUtils
;
/**
* A container object which Binds objects from one or more
...
...
@@ -308,6 +309,9 @@ public class Binder {
private
ConfigurationProperty
findProperty
(
ConfigurationPropertyName
name
,
Context
context
)
{
if
(!
StringUtils
.
hasText
(
name
.
toString
()))
{
return
null
;
}
return
context
.
streamSources
()
.
map
((
source
)
->
source
.
getConfigurationProperty
(
name
))
.
filter
(
Objects:
:
nonNull
).
findFirst
().
orElse
(
null
);
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/BinderTests.java
View file @
6d9692ff
...
...
@@ -20,7 +20,10 @@ import java.beans.PropertyEditorSupport;
import
java.time.LocalDate
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
javax.validation.Validation
;
...
...
@@ -40,6 +43,7 @@ import org.springframework.boot.context.properties.source.ConfigurationPropertyS
import
org.springframework.boot.context.properties.source.MockConfigurationPropertySource
;
import
org.springframework.core.annotation.AnnotationUtils
;
import
org.springframework.core.convert.ConversionFailedException
;
import
org.springframework.core.env.MapPropertySource
;
import
org.springframework.core.env.PropertySource
;
import
org.springframework.core.env.StandardEnvironment
;
import
org.springframework.core.io.Resource
;
...
...
@@ -301,6 +305,20 @@ public class BinderTests {
this
.
binder
.
bind
(
"foo"
,
target
);
}
@Test
@SuppressWarnings
(
"unchecked"
)
public
void
bindWithEmptyPrefixShouldIgnorePropertiesWithEmptyName
()
{
Map
<
String
,
Object
>
source
=
new
HashMap
<>();
source
.
put
(
"value"
,
"hello"
);
source
.
put
(
""
,
"bar"
);
Iterable
<
ConfigurationPropertySource
>
propertySources
=
ConfigurationPropertySources
.
from
(
new
MapPropertySource
(
"test"
,
source
));
this
.
sources
.
addAll
((
Set
)
propertySources
);
Bindable
<
JavaBean
>
target
=
Bindable
.
of
(
JavaBean
.
class
);
JavaBean
result
=
this
.
binder
.
bind
(
""
,
target
).
get
();
assertThat
(
result
.
getValue
()).
isEqualTo
(
"hello"
);
}
public
static
class
JavaBean
{
private
String
value
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment