Skip to content

Commit 748933c

Browse files
kwinmichael-o
authored andcommitted
Xpp3DomUtils#mergeIntoXpp3Dom() must not override the dominant value in case it is blank (#212)
This fixes #212 and closes #213
1 parent e2cafcf commit 748933c

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,6 @@ public static boolean isNotEmpty( String str )
290290
@Deprecated
291291
public static boolean isEmpty( String str )
292292
{
293-
return ( str == null || str.trim().length() == 0 );
293+
return ( str == null || str.length() == 0 );
294294
}
295295
}

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

+25-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,29 @@ 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 testOverwriteDominantBlankValue() throws XmlPullParserException, IOException {
119+
String lhs = "<parameter xml:space=\"preserve\"> </parameter>";
120+
121+
String rhs = "<parameter>recessive</parameter>";
122+
123+
Xpp3Dom leftDom = Xpp3DomBuilder.build( new StringReader( lhs ), new FixedInputLocationBuilder( "left" ) );
124+
Xpp3Dom rightDom = Xpp3DomBuilder.build( new StringReader( rhs ), new FixedInputLocationBuilder( "right" ) );
125+
126+
Xpp3Dom mergeResult = Xpp3DomUtils.mergeXpp3Dom( leftDom, rightDom, true );
127+
assertEquals( " ", mergeResult.getValue() );
128+
}
129+
130+
@Test
131+
public void testIsNotEmptyNegatesIsEmpty()
132+
{
133+
assertEquals( !Xpp3DomUtils.isEmpty( null ), Xpp3DomUtils.isNotEmpty( null ) );
134+
assertEquals( !Xpp3DomUtils.isEmpty( "" ), Xpp3DomUtils.isNotEmpty( "" ) );
135+
assertEquals( !Xpp3DomUtils.isEmpty( " " ), Xpp3DomUtils.isNotEmpty( " " ) );
136+
assertEquals( !Xpp3DomUtils.isEmpty( "someValue" ), Xpp3DomUtils.isNotEmpty( "someValue" ) );
137+
}
138+
115139
private static class FixedInputLocationBuilder
116140
implements Xpp3DomBuilder.InputLocationBuilder
117141
{

0 commit comments

Comments
 (0)