mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(sfn): treat null as falsy in JSONPath negation (#3497)
Co-authored-by: xujiantop-crypto <265865031+xujiantop-crypto@users.noreply.github.com>
This commit is contained in:
1 parent
8e3bd63c15
commit
c18c80e557
2 files changed
+196
-1
No files matched your search
+68
@@ -122,6 +122,74 @@ class AslExecutorPathIntrinsicsTest {
|
||||
executor.resolvePath("$.list[?(@.keep == true)]", root));
|
||||
}
|
||||
|
||||
@Test
|
||||
void filterNegationTreatsExplicitNullAndMissingPropertiesAsFalsy() throws Exception {
|
||||
JsonNode root = mapper.readTree("""
|
||||
{"items":[
|
||||
{"id":1,"session":null},
|
||||
{"id":2,"session":{"token":"active"}},
|
||||
{"id":3}
|
||||
]}
|
||||
""");
|
||||
|
||||
assertEquals(mapper.readTree("[{\"id\":1,\"session\":null},{\"id\":3}]"),
|
||||
executor.resolvePath("$.items[?(!@.session)]", root));
|
||||
}
|
||||
|
||||
@Test
|
||||
void filterNegationWorksInsideCompoundPredicates() throws Exception {
|
||||
JsonNode root = mapper.readTree("""
|
||||
{"items":[
|
||||
{"id":1,"student_programme":"A","archived_at":null},
|
||||
{"id":2,"student_programme":"B"},
|
||||
{"id":3,"student_programme":"C","archived_at":"2026-09-01"},
|
||||
{"id":4,"archived_at":null}
|
||||
]}
|
||||
""");
|
||||
|
||||
assertEquals(mapper.readTree("""
|
||||
[{"id":1,"student_programme":"A","archived_at":null},
|
||||
{"id":2,"student_programme":"B"}]
|
||||
"""),
|
||||
executor.resolvePath("$.items[?(@.student_programme && !@.archived_at)]", root));
|
||||
}
|
||||
|
||||
@Test
|
||||
void filterNegationSupportsBracketQuotedMembers() throws Exception {
|
||||
JsonNode root = mapper.readTree("""
|
||||
{"items":[
|
||||
{"id":1,"archived-at":null},
|
||||
{"id":2,"archived-at":"2026-09-01"},
|
||||
{"id":3}
|
||||
]}
|
||||
""");
|
||||
|
||||
assertEquals(mapper.readTree("[{\"id\":1,\"archived-at\":null},{\"id\":3}]"),
|
||||
executor.resolvePath("$.items[?(!@['archived-at'])]", root));
|
||||
}
|
||||
|
||||
@Test
|
||||
void filterNegationCompatibilityDoesNotRewriteComparisonsOrStringLiterals() throws Exception {
|
||||
JsonNode root = mapper.readTree("""
|
||||
{"items":[
|
||||
{"id":1,"session":null,"label":"!@.session"},
|
||||
{"id":2,"session":"active","label":"other"},
|
||||
{"id":3,"label":"!@.session"}
|
||||
]}
|
||||
""");
|
||||
|
||||
assertEquals(mapper.readTree("""
|
||||
[{"id":2,"session":"active","label":"other"},
|
||||
{"id":3,"label":"!@.session"}]
|
||||
"""),
|
||||
executor.resolvePath("$.items[?(@.session != null)]", root));
|
||||
assertEquals(mapper.readTree("""
|
||||
[{"id":1,"session":null,"label":"!@.session"},
|
||||
{"id":3,"label":"!@.session"}]
|
||||
"""),
|
||||
executor.resolvePath("$.items[?(@.label == '!@.session')]", root));
|
||||
}
|
||||
|
||||
@Test
|
||||
void recursiveDescentPreservesAndFlattensNestedArrayMatches() throws Exception {
|
||||
JsonNode root = mapper.readTree("{\"d\":{\"x\":{\"a\":[1,2]}}}");
|
||||
|
||||
Reference in new issue
Block a user