Skip to content

Commit

Permalink
defensive coding for top-level keys
Browse files Browse the repository at this point in the history
  • Loading branch information
jclausen committed Jan 18, 2025
1 parent d91c208 commit fd6fa38
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ public static Stream<IStruct> findKey( IStruct struct, String key ) {
Struct returnStruct = new Struct( Struct.TYPES.LINKED );
String keyName = entry.getKey().getName();
String[] keyParts = entry.getKey().getName().split( "\\." );
String flatMapParent = keyName.substring( 0, keyName.lastIndexOf( "." ) );
String flatMapParent = keyName.lastIndexOf( "." ) > -1 ? keyName.substring( 0, keyName.lastIndexOf( "." ) ) : "";
returnStruct.put(
Key.owner,
keyParts.length > 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@ public void testBif() {
}
};
result = StructFindKey( myStruct, "total" );
emptyResult = StructFindKey( myStruct, "bird", "all" );
""",
context );

assertTrue( variables.get( result ) instanceof Array );
assertEquals( variables.getAsArray( result ).size(), 1 );
assertEquals( variables.getAsArray( Key.of( "emptyResult" ) ).size(), 0 );
instance.executeSource(
"""
myStruct = {
Expand Down

0 comments on commit fd6fa38

Please sign in to comment.