Skip to content

Commit

Permalink
Apply cfformat changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jclausen authored and github-actions[bot] committed Jan 17, 2025
1 parent 895c764 commit 782effd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
20 changes: 7 additions & 13 deletions src/main/java/ortus/boxlang/runtime/types/XML.java
Original file line number Diff line number Diff line change
Expand Up @@ -503,20 +503,14 @@ public XML getFirstChildOfName( String childName ) {
NodeList children = node.getChildNodes();
for ( int i = 0; i < children.getLength(); i++ ) {
Node child = children.item( i );
if (
child.getNodeType() == Node.ELEMENT_NODE
&&
(
child.getNodeName().equalsIgnoreCase( childName )
||
if ( child.getNodeType() == Node.ELEMENT_NODE
&&
( child.getNodeName().equalsIgnoreCase( childName )
||
// For some reason `getPrefix` is not always populated with parsed xml, so we have to manually split the name
(
child.getNodeName().split( ":" ).length > 1
&&
child.getNodeName().split( ":" )[ 1 ].equalsIgnoreCase( childName )
)
)
) {
( child.getNodeName().split( ":" ).length > 1
&&
child.getNodeName().split( ":" )[ 1 ].equalsIgnoreCase( childName ) ) ) ) {
return new XML( child );
}
}
Expand Down
22 changes: 12 additions & 10 deletions src/test/java/ortus/boxlang/runtime/types/XMLTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -325,16 +325,17 @@ void testAssignXMLAttributes() {
assertThat( variables.get( result ) ).isInstanceOf( Struct.class );
assertThat( variables.getAsStruct( result ).get( "Product" ) ).isEqualTo( "BoxLang" );
}

@DisplayName( "It can assign an XML Atrribute" )
@Test
void testChangeXMLAttributes() {
instance.executeSource(
"""
xmlObj = xmlParse( '<Ortus Product="BoxLang"></Ortus>' );
initial = xmlObj.xmlRoot.xmlAttributes.Product;
xmlObj.xmlRoot.xmlAttributes.Product = "BoxLang Rocks!";
result = xmlObj.xmlRoot.xmlAttributes.Product;
""",
xmlObj = xmlParse( '<Ortus Product="BoxLang"></Ortus>' );
initial = xmlObj.xmlRoot.xmlAttributes.Product;
xmlObj.xmlRoot.xmlAttributes.Product = "BoxLang Rocks!";
result = xmlObj.xmlRoot.xmlAttributes.Product;
""",
context );
assertThat( variables.getAsString( Key.of( "initial" ) ) ).isEqualTo( "BoxLang" );
assertThat( variables.getAsString( result ) ).isEqualTo( "BoxLang Rocks!" );
Expand Down Expand Up @@ -384,11 +385,12 @@ void testNameSpaceValues() {
context );
//@formatter:on

assertThat( variables.getAsString( Key.of( "envelopePrefix" ) ) ).isEqualTo( "SOAP-ENV" );
assertThat( variables.getAsString( Key.of( "envelopeName" ) ) ).isEqualTo( "SOAP-ENV:Envelope" );
assertThat( variables.get( Key.of( "envelopeAttributes" ) ) ).isInstanceOf( Struct.class );
assertThat( variables.getAsStruct( Key.of( "envelopeAttributes" ) ).get( Key.of( "xmlns:SOAP-ENV" ) ) ).isEqualTo( "http://schemas.xmlsoap.org/soap/envelope/" );
assertThat( variables.getAsString( Key.of( "headerPrefix" ) ) ).isEqualTo( "SOAP-ENV" );
assertThat( variables.getAsString( Key.of( "envelopePrefix" ) ) ).isEqualTo( "SOAP-ENV" );
assertThat( variables.getAsString( Key.of( "envelopeName" ) ) ).isEqualTo( "SOAP-ENV:Envelope" );
assertThat( variables.get( Key.of( "envelopeAttributes" ) ) ).isInstanceOf( Struct.class );
assertThat( variables.getAsStruct( Key.of( "envelopeAttributes" ) ).get( Key.of( "xmlns:SOAP-ENV" ) ) )
.isEqualTo( "http://schemas.xmlsoap.org/soap/envelope/" );
assertThat( variables.getAsString( Key.of( "headerPrefix" ) ) ).isEqualTo( "SOAP-ENV" );
}

}

0 comments on commit 782effd

Please sign in to comment.