Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Fang-
Copy link
Collaborator

@Fang- Fang- commented Sep 16, 2021

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:ab has no problem parsing the empty string.
For some supported cases, like //x ([~. ~.x ~]), this is actually desired
behavior, but it results in trailing empty segments for paths ending in /.

Here we apply a +sear on top of the existing parser, that transform the /
case to produce ~, and ensures the absence of a trailing empty segment in
all other cases.

Note that we change (more fas urs:ab) to (most fas urs:ab). Since urs:ab
parses the empty string, this doesn't actually make a difference, but it does
make it more obvious that the +rear call will never crash.

Alternative approaches I attempted all resulted in much more complicated
parser, so the dumb +sear seems 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, +stap is used (directly & indirectly) in only a few places:

  • parsing for some ford runes,
  • +pa:dejs:format (currently only used in hark chat-hook parsing),
  • eyre's %subscribe command parsing (which should arguably use +pa:dejs instead).
  • scry & export path parsing in pier.c (for -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.

And reject 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:ab` has no problem parsing the empty string.
For some supported cases, like `//x` (`[~. ~.x ~]`), this is actually desired
behavior, but it results in trailing empty segments for paths ending in `/`.

Here we apply a `+sear` on top of the existing parser, that transform the `/`
case to produce `~`, and ensures the absence of a trailing empty segment in
all other cases.

Note that we change `(more fas urs:ab)` to `(most fas urs:ab)`. Since `urs:ab`
parses the empty string, this doesn't actually make a difference, but it does
make it more obvious that the `+rear` call will never crash.

Alternative approaches I attempted all resulted in much more complicated
parser, so the dumb `+sear` seems 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.

Fixes #1501.
@Fang- Fang- added the hoon label Sep 16, 2021
@Fang- Fang- requested a review from pilfer-pandex September 16, 2021 12:08
@pilfer-pandex
Copy link
Contributor

Sorry I didn't see this earlier.

@Fang- Fang- changed the base branch from master to release/next-sys October 14, 2021 21:12
@Fang- Fang- merged commit bbd0441 into release/next-sys Oct 14, 2021
@Fang- Fang- deleted the m/righteous-paths branch October 14, 2021 21:12
@Fang- Fang- mentioned this pull request Dec 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

stab doesn't parse empty path properly

2 participants