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
233ef67a
Commit
233ef67a
authored
May 23, 2017
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow nested square brackets in map key when binding
Fixes gh-3202
parent
e8170cf0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
8 deletions
+39
-8
ConfigurationPropertyName.java
.../context/properties/source/ConfigurationPropertyName.java
+15
-8
MapBinderTests.java
...ramework/boot/context/properties/bind/MapBinderTests.java
+9
-0
ConfigurationPropertyNameTests.java
...ext/properties/source/ConfigurationPropertyNameTests.java
+15
-0
No files found.
spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java
View file @
233ef67a
...
@@ -513,17 +513,24 @@ public final class ConfigurationPropertyName
...
@@ -513,17 +513,24 @@ public final class ConfigurationPropertyName
int
start
=
0
;
int
start
=
0
;
boolean
indexed
=
false
;
boolean
indexed
=
false
;
int
length
=
name
.
length
();
int
length
=
name
.
length
();
int
openBracketCount
=
0
;
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
char
ch
=
name
.
charAt
(
i
);
char
ch
=
name
.
charAt
(
i
);
if
(
indexed
&&
ch
==
']'
)
{
if
(
ch
==
']'
)
{
processElement
(
processor
,
name
,
start
,
i
+
1
,
indexed
);
openBracketCount
--;
start
=
i
+
1
;
if
(
openBracketCount
==
0
)
{
indexed
=
false
;
processElement
(
processor
,
name
,
start
,
i
+
1
,
indexed
);
start
=
i
+
1
;
indexed
=
false
;
}
}
}
else
if
(!
indexed
&&
ch
==
'['
)
{
else
if
(
ch
==
'['
)
{
processElement
(
processor
,
name
,
start
,
i
,
indexed
);
openBracketCount
++;
start
=
i
;
if
(!
indexed
)
{
indexed
=
true
;
processElement
(
processor
,
name
,
start
,
i
,
indexed
);
start
=
i
;
indexed
=
true
;
}
}
}
else
if
(!
indexed
&&
ch
==
separator
)
{
else
if
(!
indexed
&&
ch
==
separator
)
{
processElement
(
processor
,
name
,
start
,
i
,
indexed
);
processElement
(
processor
,
name
,
start
,
i
,
indexed
);
...
...
spring-boot/src/test/java/org/springframework/boot/context/properties/bind/MapBinderTests.java
View file @
233ef67a
...
@@ -503,6 +503,15 @@ public class MapBinderTests {
...
@@ -503,6 +503,15 @@ public class MapBinderTests {
assertThat
(
map
.
get
(
0
)).
containsExactly
(
8
,
9
);
assertThat
(
map
.
get
(
0
)).
containsExactly
(
8
,
9
);
}
}
@Test
public
void
bindingWithSquareBracketMap
()
throws
Exception
{
MockConfigurationPropertySource
source
=
new
MockConfigurationPropertySource
();
source
.
put
(
"foo.[x [B] y]"
,
"[ball]"
);
this
.
sources
.
add
(
source
);
Map
<
String
,
String
>
map
=
this
.
binder
.
bind
(
"foo"
,
STRING_STRING_MAP
).
get
();
assertThat
(
map
).
containsEntry
(
"x [B] y"
,
"[ball]"
);
}
private
<
K
,
V
>
Bindable
<
Map
<
K
,
V
>>
getMapBindable
(
Class
<
K
>
keyGeneric
,
ResolvableType
valueType
)
{
private
<
K
,
V
>
Bindable
<
Map
<
K
,
V
>>
getMapBindable
(
Class
<
K
>
keyGeneric
,
ResolvableType
valueType
)
{
ResolvableType
keyType
=
ResolvableType
.
forClass
(
keyGeneric
);
ResolvableType
keyType
=
ResolvableType
.
forClass
(
keyGeneric
);
return
Bindable
.
of
(
ResolvableType
.
forClassWithGenerics
(
Map
.
class
,
keyType
,
valueType
));
return
Bindable
.
of
(
ResolvableType
.
forClassWithGenerics
(
Map
.
class
,
keyType
,
valueType
));
...
...
spring-boot/src/test/java/org/springframework/boot/context/properties/source/ConfigurationPropertyNameTests.java
View file @
233ef67a
...
@@ -175,6 +175,21 @@ public class ConfigurationPropertyNameTests {
...
@@ -175,6 +175,21 @@ public class ConfigurationPropertyNameTests {
ConfigurationPropertyName
.
of
(
"bar]"
);
ConfigurationPropertyName
.
of
(
"bar]"
);
}
}
@Test
public
void
ofNameWhenMultipleMismatchedBrackets
()
throws
Exception
{
this
.
thrown
.
expect
(
IllegalArgumentException
.
class
);
this
.
thrown
.
expectMessage
(
"is not valid"
);
ConfigurationPropertyName
.
of
(
"[a[[[b]ar]"
);
}
@Test
public
void
ofNameWhenNestedBrackets
()
throws
Exception
{
ConfigurationPropertyName
name
=
ConfigurationPropertyName
.
of
(
"foo[a[c][[b]ar]]"
);
assertThat
(
name
.
toString
()).
isEqualTo
(
"foo[a[c][[b]ar]]"
);
assertThat
(
name
.
getElement
(
0
,
Form
.
ORIGINAL
)).
isEqualTo
(
"foo"
);
assertThat
(
name
.
getElement
(
1
,
Form
.
ORIGINAL
)).
isEqualTo
(
"a[c][[b]ar]"
);
}
@Test
@Test
public
void
ofNameWithWhitespaceInName
()
throws
Exception
{
public
void
ofNameWithWhitespaceInName
()
throws
Exception
{
this
.
thrown
.
expect
(
IllegalArgumentException
.
class
);
this
.
thrown
.
expect
(
IllegalArgumentException
.
class
);
...
...
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