-
Notifications
You must be signed in to change notification settings - Fork 64
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
Stricter pointer/ref checks & public segment encoding/decoding methods #47
Comments
|
Are you open to reopening this for the sake of the first of my two requests? If so, it would be nice to be able to avoid throwing an error in the case where tildes are not followed by 0 or 1 since it is not technically illegal, and I also have a specific use-case for this (using tildes to surround variables within JSON references which may be substituted at some point, e.g., locale). |
I thought I handled them. Also, I'm not throwing an error for tildes followed by something other than 0 or 1, just returning false. |
Sorry about that then--haven't looked too carefully yet. |
As far as the tildes and error though, what I mean is that since |
Good point. All of this being said, if you have an invalid reference, for any reason, finding/resolving references will not process them so it's not really a big change. I think if a user expects to find/resolve a reference and it's not happening, advising them to use Right now, these were the changes related to closing this issue. Please confirm that I've addressed everything:
Let me know if there is more and we'll reopen this. |
It could be handled as JS does with As far as |
Further to the discussion of finding invalid pointers, I think |
So you want me to remove the exposed As for needing to know to use In the end, I just want |
If I understand this correctly, these will be the next steps:
|
As far as |
Okay. So keep the new methods as-is. :) What about the configuration option to make |
Everything you said on |
And maybe just rename |
The more I think about it, |
ok, cool. |
You saw my other comment about accepting another argument to |
Yup. |
As I'm implementing this, I'm not sure this is very useful. I can see how having |
I do realize that you could manually do something like: if (!JsonRefs.isPtr(val) && JsonRefs.isPtr(val, false)) {
// This is a JSON Pointer like value that is strictly invalid but structurally valid
} If that's the use case you want to allow, I can make that happen. Heck, as I type this I think this is how I will need to do this for |
The reason I ask is I'm not sure why you'd use this directly unless you were in the business of rewriting the logic of |
I guess I was mistaken in my OP though in that the spec does state it being a requirement for escaping:
Nevertheless, I still think that if we have a public function |
What do you think about an argument that basically says "throw an Error with the details as to why the JSON Pointer is invalid"? That seems more useful and |
Sure, as long as it is exhaustive or only reports the tilde errors if there are no other errors... |
I'll get something together and we can discuss then. |
Let me run this by you first. Basically, I think the real features we want are the ability to identify why a candidate is not a valid JSON Pointer/Reference and to make it so that Is that right? The reason I ask is because we can make it so that |
Yeah, I think that is right--though maybe one more addition that would be nice would be a chance for |
I just re-read the JSON Pointer spec again and I'm not sure that a dangling That being said, I think we should remove more strict I'll be in the json-refs Gitter channel today so we can chat there if need be. (I'll update this thread for posterity if need be.) |
I'm an idiot. Disregard the part about removing token validation. JSON Pointer values should always be encoded and decoding only happens at the time at which you evaluate the JSON Pointer value. That being said, it will stay in. |
`#isPtr` and `#isRef` now have a second optional argument that dictates whether the function should throw an `Error` with the details as to why the provided value failed validation. See #47
I have two commits associated with this issue. I think I've handled the scenarios we wanted. Here are the changes:
Please let me know if I missed something or if you think things should work differently. |
Sorry getting to you now--not a good health day. Everything looks good... If you're up for it, I think:
(Sorry, I'm not submitting PR's for these, but dealing with chronic fatigue.) |
Sorry to hear about your health issues, I hope you're feeling better. As for not submitting PRs, no sweat at all. Here are my responses:
Unless you have a compelling reason why 2 should be in json-refs, I'm inclined to pass for now since it's fairly simple to do outside of json-refs. |
I've updated the jsdoc to be more detailed in the If I don't hear from you in a few hours, I will likely cut |
My use case is primarily for i18n. Usually locale files are stored separately according to language code, so if you want to include the needed locale file by JR, you need to substitute a variable within the JR with the current (dynamically detected) locale. (I then have JRs elsewhere in the main JSON document to target specific translated strings from within the JR'd locale file.) While I think dynamic variable substitution ought to be a fairly general problem (whether i18n or something else) and separate calls would add some overhead in needing to traverse twice, there is admittedly no formal JR-spec'd way to do this, and as you've already made the use case possible through other means, it's your call I think on whether this use case sounds general purpose enough. |
I was just about to tell you that I didn't think this should be in this library but I can see how without something, it would be painful to use Actually, as I type that you could use Do you think this feature should halt |
No, please don't let it hold you back. Thank you for making the functionality possible, btw, and thanks also for being very responsive on all of the feedback/ideas! |
No sweat. I'll create a new issue with this request in it and tag you so you can fill in the gaps in my explanation if need be. |
That'd be great... (Note: mentioned in #54 ) |
Two related issues:
The JSON Pointer spec, in turn, says about JSON Pointers:
I would think therefore, that when executing
isPtr
upon encountering any tildes not followed by0
or1
,false
should be given. Similarly when executingisRef
, especially if we detect that the target document is indeed JSON. This will also have the consequence of potentially throwing for this reason inpathFromPtr
.The spec seems to make no mention of any requirement to do this, however:
...but I think that when one asks whether something is a pointer or reference, it is good to know whether it has had proper escaping.
2 .I also think that as the
JsonRefs
tool, you should make the segment encoding and decoding functions public.The text was updated successfully, but these errors were encountered: