Skip to content

Commit

Permalink
Xpp3DomUtils#mergeIntoXpp3Dom() must not override the dominant value …
Browse files Browse the repository at this point in the history
…in case it is blank (#212)

This fixes #212 and closes #213
  • Loading branch information
kwin authored and michael-o committed Oct 10, 2022
1 parent e2cafcf commit 748933c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,6 @@ public static boolean isNotEmpty( String str )
@Deprecated
public static boolean isEmpty( String str )
{
return ( str == null || str.trim().length() == 0 );
return ( str == null || str.length() == 0 );
}
}
26 changes: 25 additions & 1 deletion src/test/java/org/codehaus/plexus/util/xml/Xpp3DomUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@

import static org.junit.Assert.assertEquals;

import java.io.IOException;
import java.io.StringReader;

import org.codehaus.plexus.util.xml.pull.XmlPullParser;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.junit.Test;

/**
Expand Down Expand Up @@ -111,7 +113,29 @@ public void testCombineKeys()
assertEquals( "RHS", mergeResult.getChildren( "property" )[2].getChild( "value" ).getValue() );
assertEquals( "right", p2.getChild( "value" ).getInputLocation() );
}


@Test
public void testOverwriteDominantBlankValue() throws XmlPullParserException, IOException {
String lhs = "<parameter xml:space=\"preserve\"> </parameter>";

String rhs = "<parameter>recessive</parameter>";

Xpp3Dom leftDom = Xpp3DomBuilder.build( new StringReader( lhs ), new FixedInputLocationBuilder( "left" ) );
Xpp3Dom rightDom = Xpp3DomBuilder.build( new StringReader( rhs ), new FixedInputLocationBuilder( "right" ) );

Xpp3Dom mergeResult = Xpp3DomUtils.mergeXpp3Dom( leftDom, rightDom, true );
assertEquals( " ", mergeResult.getValue() );
}

@Test
public void testIsNotEmptyNegatesIsEmpty()
{
assertEquals( !Xpp3DomUtils.isEmpty( null ), Xpp3DomUtils.isNotEmpty( null ) );
assertEquals( !Xpp3DomUtils.isEmpty( "" ), Xpp3DomUtils.isNotEmpty( "" ) );
assertEquals( !Xpp3DomUtils.isEmpty( " " ), Xpp3DomUtils.isNotEmpty( " " ) );
assertEquals( !Xpp3DomUtils.isEmpty( "someValue" ), Xpp3DomUtils.isNotEmpty( "someValue" ) );
}

private static class FixedInputLocationBuilder
implements Xpp3DomBuilder.InputLocationBuilder
{
Expand Down

0 comments on commit 748933c

Please sign in to comment.