-
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
Better dumping #1993
base: master
Are you sure you want to change the base?
Better dumping #1993
Conversation
Rebased and force pushed to run Travis after the fixes. |
Is there anything I can do to help this get reviewed & in-tree? |
I'll take a look as soon as I can, which might not be till next week :( |
bump again |
Rebump. |
Also commented to make the implementation clearer.
Behavior is the same, but this form is easier to understand and make robust.
It's supposed to print raw, compact, and with no decoration or trailing newline. Previously, it would print JSON formatted, compact, with no trailing newline and no easy way to obtain one, and ignoring the --ascii-output / -a flag.
Escapes are still printed whenever characters outside the ASCII plane are encountered. To avoid ambiguity, backslash is the only ASCII character escaped (as `\\`). Fixes jqlang#1788, properly this time. Closes jqlang#1789.
Rebased with manual review over new commits (24564b2 got close to this patch's lines), and still passes tests. (AppVeyor is experiencing pacman |
This PR addresses #2063 |
A fair amount of refactoring went into this PR to make each step clear and prevent issues like those in #1789, where escaping wasn't correctly handled. I'll summarize the non-bugfix commits, and the commit messages for the fixes follow.
jvp_dump_string
changed from consuming a boolean-useint ascii_only
toenum jv_print_flags
int flags
. This makesjvp_dump_string
more capable of responding to input formats, reducing pressure on consumers to get it right.jvp_dump_char
is factored out fromjvp_dump_string
, making future increases in complexity to both clearer.JV_PRINT_RAW
andJV_PRINT_RAWCOLOR
flags are introduced toenum jv_print_flags
, consolidating prints inmain.c
'sprocess
tojv_dump(result, dumpopts)
. TheJV_PRINT_RAW
flag is not passed down to recursivejv_dump*
calls for arrays or objects.JV_PRINT_RAWCOLOR
is unset by default and has no API currently, but is there if colored, raw output is desired in the future.JV_PRINT_RAWCOLOR
avoids problems with colored output by noticing when a type would be raw printed and disablingJV_PRINT_COLOR
before that's a problem.Fix
stderr/0
builtin to match documentationf_stderr
, instead of callingjv_dumpf(jv_copy(input), stderr, 0)
, now has astderr_cb
setup similar tof_debug
that it uses identically. The only functional difference ismain.c
'sstderr_cb
:Bring
--raw-output
and--ascii-output
to agreementjvp_dump_char
gains a boolean-useint raw
parameter that is used to always print ASCII characters (save backslash) and turn on escapes for everything else.jvp_dump_string
learns to handle raw strings in the non-(raw && !ascii_only)
path. Due to the earlier changes, every other use of raw strings is immediately corrected.This change is