hoon: correctly parse empty path #5227
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
And reject non-empty paths ending in empty segments.
The following cases were being parsed incorrectly:
/represents the empty path,~. This was being parsed into[~. ~]/x/is not valid. This was being parsed into[~.x ~. ~]This happens because
urs:abhas no problem parsing the empty string.For some supported cases, like
//x([~. ~.x ~]), this is actually desiredbehavior, but it results in trailing empty segments for paths ending in
/.Here we apply a
+searon top of the existing parser, that transform the/case to produce
~, and ensures the absence of a trailing empty segment inall other cases.
Note that we change
(more fas urs:ab)to(most fas urs:ab). Sinceurs:abparses the empty string, this doesn't actually make a difference, but it does
make it more obvious that the
+rearcall will never crash.Alternative approaches I attempted all resulted in much more complicated
parser, so the dumb
+searseems preferable.We do eat the performance cost of an additional list traversal (in
+rear)with this change, but that is probably not the end of the world.
If anyone can golf a cute smol parser that solves for this, I'd be happy to use that instead.
All tests seem to pass, but note that
/x/was previously a valid path, and will no longer parse after this change. Luckily,+stapis used (directly & indirectly) in only a few places:+pa:dejs:format(currently only used in hark chat-hook parsing),%subscribecommand parsing (which should arguably use+pa:dejsinstead).-X)I believe none of these cases expect/care about trailing empty segments, and will continue to work fine with the new behavior.
Fixes #1501.