Created by: Adam5Wu
I am proposing a small adjustment to the nest level counting so that it is more coherent:
- Simple values (boolean, string, number) are of nest level 0
- Each layer of object/array increase the nest level by 1
This resolves the nest level loophole when programatically generating nested structures: Before:
- when inserting a simple value (nest level 0) to a flat array (nest level 0)
- The result can be serialized and parsed back with nest limit of 0
- Nest level: 0 + 0 = 0
- But when inserting a flat object (nest level 0) to a flat array (nest level 0)
- The result cannot be serialized and parsed back with nest limit of 0
- Nest level: 0 + 0 = 1
After:
- Inserting a single value (nest level 0) to a flat object (nest level 1):
- The result can be serialized and parsed back with nest limit of 1
- Nest level: 0 + 1 = 1
- Inserting a flat object (nest level 1) to a flat array (nest level 1):
- The result can be serialized and parsed back with nest limit of 2
- Nest level: 1 + 1 = 2
As a (possibly good) side effect, this patch also makes the parseAnythingToUnsafe() method unnecessary.