Skip to content

Commit cea765d

Browse files
committed
Always preserve dominant node value (even if empty)
This closes codehaus-plexus#216
1 parent 8a9147a commit cea765d

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-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

+17-1
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818

1919
import static org.junit.Assert.assertEquals;
2020

21+
import java.io.IOException;
2122
import java.io.StringReader;
2223

2324
import org.codehaus.plexus.util.xml.pull.XmlPullParser;
25+
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
2426
import org.junit.Test;
2527

2628
/**
@@ -111,7 +113,21 @@ public void testCombineKeys()
111113
assertEquals( "RHS", mergeResult.getChildren( "property" )[2].getChild( "value" ).getValue() );
112114
assertEquals( "right", p2.getChild( "value" ).getInputLocation() );
113115
}
114-
116+
117+
@Test
118+
public void testPreserveDominantEmptyNode() throws XmlPullParserException, IOException
119+
{
120+
String lhs = "<parameter></parameter>";
121+
122+
String rhs = "<parameter>recessive</parameter>";
123+
124+
Xpp3Dom leftDom = Xpp3DomBuilder.build( new StringReader( lhs ), new FixedInputLocationBuilder( "left" ) );
125+
Xpp3Dom rightDom = Xpp3DomBuilder.build( new StringReader( rhs ), new FixedInputLocationBuilder( "right" ) );
126+
127+
Xpp3Dom mergeResult = Xpp3DomUtils.mergeXpp3Dom( leftDom, rightDom, true );
128+
assertEquals( "", mergeResult.getValue() );
129+
}
130+
115131
private static class FixedInputLocationBuilder
116132
implements Xpp3DomBuilder.InputLocationBuilder
117133
{

0 commit comments

Comments
 (0)