-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
implode: Better invalid input validation and handling #2646
Conversation
TODO:
|
@wader - My (perhaps flawed) understanding has been that one of the reasons why jq's In any case, I think it would helpful to track the impact on speed of updates to One reasonable approach would be to take a standard JSON test file (e.g. jeopardy.json - see https://github.com/jqlang/jq/wiki/X---Experimental-Benchmarks) and treat it as raw text. jqMaster:
jqMaster with NDEBUG
|
In this case i think it's a bug, at least the cli should never assert like this. By reading the code i looks like the idea is that the builtins wrapper functions (also i said util.c which is wrong,
Yes track that is a good idea |
tests/jq.test
Outdated
|
||
map(try implode catch .) | ||
[123,["a"]] | ||
["implode input must be an array","string (\"a\") codepoint must be a number"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe should be formulated as string ("a") is not a number codepoint
etc?
7657055
to
e47d516
Compare
Rebased and now also replaces surrogate pair range with replacement character, same as gojq. But i noticed now that gojq throws error on negative and > 1114111 |
What do ppl think about invalid and surrogate pair numbers? error or replacement? |
I think that asking questions like that is sure to cause strenuous debate. Somehow it didn't -- maybe no one noticed you asking. 😆 Anyways, my preference would be replacement (think of the Postel principle), but wait! no! error! (because the Postel principle causes more troubles than it saves, and because we want to be able to validate JSON with just EDIT: Well, if we don't document this then we're free to change the behavior later. I say go for replacement for now. |
4fdab77
to
77dba74
Compare
😄 Ok! that is the current behaviour in the PR. @itchyny not sure if you want to adjust gojq to behave the same, current it throws error for > 1114111 and < 0 on implode. |
Not sure what is going on with github, pushed new commit but still says conflict and no actions have run yet... i guess we wait a bit |
@wader github is reporting a legitimate conflict: this PR is based on 98f709d, and after that commit, 1cf6515 on master adds lines at the end of Basically, |
77dba74
to
b214e2b
Compare
Ah thanks, that makes sense. Think got confused that i fixed the conflict in jq.test and pushed a while later and there was more commits to master cause a conflict in jq.test again :) |
c1ac128
to
6fbf341
Compare
Assertions in |
100c3f7
to
80d8e2f
Compare
80d8e2f
to
fac4e27
Compare
Think this is ready now, only thing i don't like is the error message |
How about "only numeric Unicode codepoints may be imploded"? Or something to that effect. The point being to give the user a clue that the error has to do with |
And yes, modulo any improvement you want to make to that error message, this is ready! |
Error on non-number and nan codepoint, would asserd before Replace negative codepoint and surrogate range with unicode replacement character, would assert before Fixes jqlang#1160
fac4e27
to
58e05d8
Compare
Changed to On the topic of errors: it would be great if more error messages had some kind of "source" prefix etc like function name. Now a days i think i've learned to recognize most commcon errors to know where they usually come from :) how hard would a stack trace be with source location etc? need to track more things? sorry for derailing, maybe should open an issue about it to collect stuff? |
Oh, I've wanted a stack trace, yeah. It would have to have column numbers too, not just line numbers. |
Thanks!! |
`[[]] | implode` crash was fixed in 1.7 by jqlang/jq#2646 `[limit(0; 1, 2, 3)]` yielding 1,2 instead of nothing fixed in 1.7 by jqlang/jq#2316 `limit/2` will throw error on negative limit once jqlang/jq#3181 is merged
Error on non-number codepoint, asserted before
Replace negative codepoint and surrogate range with unicode replacement character, asserted before
Fixes #1160