Skip to content

Commit 67ac243

Browse files
kwinmichael-o
authored andcommitted
Xpp3DomUtils#mergeIntoXpp3Dom() must not override the dominant value in case it is empty (#216)
This fixes #216 and closes #217
1 parent 748933c commit 67ac243

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/main/java/org/codehaus/plexus/util/xml/Xpp3DomUtils.java

-8
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ public void writeToSerializer( String namespace, XmlSerializer serializer, Xpp3D
9595
* </ol></li>
9696
* <li> If mergeSelf == true
9797
* <ol type="A">
98-
* <li> if the dominant root node's value is empty, set it to the recessive root node's value</li>
99-
* <li> For each attribute in the recessive root node which is not set in the dominant root node, set it.</li>
10098
* <li> Determine whether children from the recessive DOM will be merged or appended to the dominant DOM as
10199
* siblings (flag=mergeChildren).
102100
* <ol type="i">
@@ -140,12 +138,6 @@ private static void mergeIntoXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive, Boole
140138

141139
if ( mergeSelf )
142140
{
143-
if ( isEmpty( dominant.getValue() ) && !isEmpty( recessive.getValue() ) )
144-
{
145-
dominant.setValue( recessive.getValue() );
146-
dominant.setInputLocation( recessive.getInputLocation() );
147-
}
148-
149141
String[] recessiveAttrs = recessive.getAttributeNames();
150142
for ( String attr : recessiveAttrs )
151143
{

src/test/java/org/codehaus/plexus/util/xml/Xpp3DomUtilsTest.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public void testCombineKeys()
115115
}
116116

117117
@Test
118-
public void testOverwriteDominantBlankValue() throws XmlPullParserException, IOException {
118+
public void testPreserveDominantBlankValue() throws XmlPullParserException, IOException {
119119
String lhs = "<parameter xml:space=\"preserve\"> </parameter>";
120120

121121
String rhs = "<parameter>recessive</parameter>";
@@ -127,6 +127,20 @@ public void testOverwriteDominantBlankValue() throws XmlPullParserException, IOE
127127
assertEquals( " ", mergeResult.getValue() );
128128
}
129129

130+
@Test
131+
public void testPreserveDominantEmptyNode() throws XmlPullParserException, IOException
132+
{
133+
String lhs = "<parameter></parameter>";
134+
135+
String rhs = "<parameter>recessive</parameter>";
136+
137+
Xpp3Dom leftDom = Xpp3DomBuilder.build( new StringReader( lhs ), new FixedInputLocationBuilder( "left" ) );
138+
Xpp3Dom rightDom = Xpp3DomBuilder.build( new StringReader( rhs ), new FixedInputLocationBuilder( "right" ) );
139+
140+
Xpp3Dom mergeResult = Xpp3DomUtils.mergeXpp3Dom( leftDom, rightDom, true );
141+
assertEquals( "", mergeResult.getValue() );
142+
}
143+
130144
@Test
131145
public void testIsNotEmptyNegatesIsEmpty()
132146
{

0 commit comments

Comments
 (0)