@@ -89,8 +89,6 @@ public boolean check(HttpServerExchange exchange, RequestContext context, DBObje
89
89
if (args instanceof BasicDBList ) {
90
90
boolean patching = context .getMethod () == RequestContext .METHOD .PATCH ;
91
91
92
- BasicDBList conditions = filterMissingOptionalAndNullNullableConditions ((BasicDBList ) args , context .getContent ());
93
-
94
92
if (patching ) {
95
93
// if patching the keys can use the dot notation
96
94
// example {"a.b": 1, "a.c": 2}
@@ -99,9 +97,15 @@ public boolean check(HttpServerExchange exchange, RequestContext context, DBObje
99
97
DBObject content = context .getContent ();
100
98
101
99
return !content .keySet ().stream ().anyMatch (key -> {
102
- return !applyConditions (conditions , remapJson (key , content .get (key )), context );
100
+ DBObject remappedContent = remapJson (key , content .get (key ));
101
+
102
+ BasicDBList conditions = filterMissingOptionalAndNullNullableConditions ((BasicDBList ) args , remappedContent , true );
103
+
104
+ return !applyConditions (conditions , remappedContent , context );
103
105
});
104
106
} else {
107
+ BasicDBList conditions = filterMissingOptionalAndNullNullableConditions ((BasicDBList ) args , context .getContent (), false );
108
+
105
109
return applyConditions (conditions , context .getContent (), context );
106
110
}
107
111
} else {
@@ -239,7 +243,7 @@ private boolean applyConditions(BasicDBList conditions, DBObject json, final Req
239
243
});
240
244
}
241
245
242
- private BasicDBList filterMissingOptionalAndNullNullableConditions (BasicDBList conditions , DBObject content ) {
246
+ private BasicDBList filterMissingOptionalAndNullNullableConditions (BasicDBList conditions , DBObject content , boolean patching ) {
243
247
// nullPaths contains all paths that result to null and condition is nullable or optional
244
248
Set <String > nullPaths = new HashSet <>();
245
249
@@ -283,7 +287,7 @@ private BasicDBList filterMissingOptionalAndNullNullableConditions(BasicDBList c
283
287
}
284
288
}
285
289
286
- if (optional ) {
290
+ if (optional || patching ) {
287
291
Object _path = ((BasicDBObject ) condition ).get ("path" );
288
292
289
293
if (_path != null && _path instanceof String ) {
@@ -452,29 +456,31 @@ private boolean checkRegex(DBObject json, String path, String regex, boolean opt
452
456
try {
453
457
props = JsonUtils .getPropsFromPath (_json , path );
454
458
} catch (IllegalArgumentException ex ) {
459
+ LOGGER .debug ("checkRegex({}, {}) -> {}" , path , regex , ex .getMessage ());
460
+ context .addWarning ("checkRegex condition failed: path: " + path + ", regex: " + regex + ", got: " + ex .getMessage ());
455
461
return false ;
456
462
}
457
463
458
- // props is null when path does not exist.
459
- if (props == null ) {
460
- return optional ;
461
- }
462
-
463
464
boolean ret ;
464
465
465
- Pattern p = Pattern .compile (regex , Pattern .CASE_INSENSITIVE );
466
+ // props is null when path does not exist.
467
+ if (props == null ) {
468
+ ret = optional ;
469
+ } else {
470
+ Pattern p = Pattern .compile (regex , Pattern .CASE_INSENSITIVE );
466
471
467
- ret = props .stream ().allMatch ((Optional <Object > prop ) -> {
468
- if (prop == null ) {
469
- return optional ;
470
- }
472
+ ret = props .stream ().allMatch ((Optional <Object > prop ) -> {
473
+ if (prop == null ) {
474
+ return optional ;
475
+ }
471
476
472
- if (prop .isPresent ()) {
473
- return p .matcher (JsonUtils .serialize (prop .get ())).find ();
474
- } else {
475
- return nullable ;
476
- }
477
- });
477
+ if (prop .isPresent ()) {
478
+ return p .matcher (JsonUtils .serialize (prop .get ())).find ();
479
+ } else {
480
+ return nullable ;
481
+ }
482
+ });
483
+ }
478
484
479
485
LOGGER .debug ("checkRegex({}, {}) -> {} -> {}" , path , regex , props , ret );
480
486
0 commit comments