Skip to content

Commit 819df0a

Browse files
committed
Update document.dart
1 parent cbe7ec3 commit 819df0a

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

packages/nitrite/lib/src/collection/document.dart

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,10 @@ class _NitriteDocument extends Document {
392392
}
393393

394394
var key = splits[0];
395+
if (key.isNullOrEmpty) {
396+
throw ValidationException("Invalid key provided");
397+
}
398+
395399
if (splits.length == 1) {
396400
// if last key, simply remove from the current document
397401
remove(key);
@@ -448,8 +452,13 @@ class _NitriteDocument extends Document {
448452
return null;
449453
}
450454

455+
var key = path[0];
456+
if (key.isNullOrEmpty) {
457+
throw ValidationException("Invalid key provided");
458+
}
459+
451460
// get current level value and scan to next level using remaining keys
452-
return _recursiveGet(this[path[0]], path.sublist(1));
461+
return _recursiveGet(this[key], path.sublist(1));
453462
}
454463

455464
dynamic _recursiveGet(dynamic value, List<String> splits) {
@@ -463,6 +472,11 @@ class _NitriteDocument extends Document {
463472

464473
if (value is _NitriteDocument) {
465474
// if the current level value is document, scan to the next level with remaining keys
475+
var key = splits[0];
476+
if (key.isNullOrEmpty) {
477+
throw ValidationException("Invalid key provided");
478+
}
479+
466480
return _recursiveGet(value[splits[0]], splits.sublist(1));
467481
}
468482

@@ -471,6 +485,10 @@ class _NitriteDocument extends Document {
471485

472486
// get the first key
473487
var key = splits[0];
488+
if (key.isNullOrEmpty) {
489+
throw ValidationException("Invalid key provided");
490+
}
491+
474492
if (_isInteger(key)) {
475493
// if the current key is an integer
476494
int index = _asInteger(key);

0 commit comments

Comments
 (0)