Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't overwrite blank (but non-empty) dominant values during mergeXpp3Dom #213

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 );
michael-o marked this conversation as resolved.
Show resolved Hide resolved
}
}
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