Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hash in path #5

Open
brettz9 opened this issue Jun 23, 2024 · 2 comments
Open

Hash in path #5

brettz9 opened this issue Jun 23, 2024 · 2 comments

Comments

@brettz9
Copy link

brettz9 commented Jun 23, 2024

Hi,

Thanks for your library--it's working well for me.

Just a heads up though that although your README mentions use with the # character, as expected per the spec, the internal PREFIX_RE regular expression doesn't allow such paths (it only allows a hash at the end).

@0xfede
Copy link
Member

0xfede commented Jun 27, 2024

Hi, I'm not sure I understand the problem: can you provide an example?

@brettz9
Copy link
Author

brettz9 commented Jun 27, 2024

Maybe I am mistaken, but shouldn't the fragments such as listed at https://datatracker.ietf.org/doc/html/rfc6901#section-6 work, e.g., pointer({abc: true}, '#/abc')?

The path in your example at https://github.com/vivocha/jsonref?tab=readme-ov-file#pointerdata-path--value suggests this form of fragment identifier should work (i.e., #/prop1/prop2):

`path`, either a string (`#/prop1/prop2`) or an array of path components (`[ "#", "prop1", "prop2" ]`

This doesn't work currently because you have the following code in src/pointer.ts:

      const PREFIX_RE: RegExp = /^(0|[1-9][0-9]*?)([#]?)$/;
// ...
      const match = prefix.match(PREFIX_RE);
      if (!match) {
        throw new SyntaxError(`Bad prefix ${prefix}`);
      }

...and that regular expression, PREFIX-RE will not allow # at the beginning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants