Weaving swatch references restore category names containing slashes incorrectly
Level 2 · node · API · Incorrect escape substitution order in structured path representation
Scenario
A fictional weaving swatch exhibition stores category paths as arrays of strings and exposes them as single path strings in its preview list. The display restores the category path from each string. Ordinary names and names containing tildes work, but category names containing slashes change when restored. Review the list-building flow and the contract of the string conversion functions together.
Requirements
preview(selections) converts each {label, segments} item to {label, pointer} in input order. segments is an array of strings. The path representation encodes each tilde in a segment as ~0 and each slash as ~1, then joins the encoded segments with a slash before each segment. An empty array produces an empty string; empty segments remain intact. locateSegments(pointer) restores valid strings of this format to the original segment array. Do not mutate inputs; preserve both existing interfaces.
Acceptance criteria
- Represent and restore ordinary category names and names containing tildes using the exact path string.
- Round-trip a name containing a slash as one segment.
- Restore names containing tildes, slashes and strings resembling escape notation without alteration.
- Distinguish empty arrays from empty segments while preserving list order and original inputs.