Repository navigation
Conversation
However, because str.lstrip(separator) removes any leading character present anywhere in separator, passing a multi-character delimiter breaks token boundaries: Character-set vs. token matching: Given separator="ab", str.lstrip("ab") strips any sequence of 'a' and 'b' characters from the start of the string. If the first path segment legitimately begins with a partial prefix of that delimiter (e.g., "appleabkey"), the leading 'a' is erroneously stripped, mutating the segment into "pple". Downstream CRUD impact: Because the path parser silently alters the key name before tree traversal, read operations (get(), search()) either fail to find existing keys or silently resolve to an unintended sibling key ("pple"). Similarly, write and delete operations (new(), set(), delete()) traverse the wrong branch, creating corrupted structures or mutating unrelated data without raising an exception.
Iterative Whole-Token Removal: Instead of stripping characters belonging to the delimiter set, the algorithm must check whether the string begins with the exact delimiter sequence and slice off the entire token length (len(separator)) iteratively: while path.startswith
Repeated Leading Delimiters: Because the prefix check runs in a loop, consecutive full delimiter tokens (e.g., "ababappleabkey") are still stripped completely down to "appleabkey", while a trailing partial match (e.g., "abaappleabkey") strips only the complete "ab" token and preserves "aapple". Single-Character Delimiters: When
|
_split_path()currently passes the separator tostr.lstrip(), which removes individual separator characters. With separatorab,appleabkeybecomespple/key. If both keys exist,get()silently returns the wrong value;new()can create the wrong key.Strip only complete leading separator tokens before splitting the path. Repeated whole separators still work. Single-character separators, list paths,
Noneand empty-separator behavior are preserved.The regression tests cover partial prefixes, repeated leading separators,
get(),new(),set(),delete()andsearch(). Five tests fail against unchanged master and pass with the fix; a separate control checks existing separator behavior.Validation:
AI assistance was used to prepare and locally test this change. The reproduction uses synthetic inputs, not a claimed production incident.