[pretty-print] fix printing of quoted strings that have escaped characters

Fixes #354
pull/356/head
Timothy Stack 8 years ago
parent 2e68f48a18
commit 41a2eed239

File diff suppressed because it is too large Load Diff

@ -93,7 +93,7 @@ bool data_scanner::tokenize2(pcre_context &pc, data_token_t &token_out)
/*!re2c
re2c:yyfill:enable = 0;
SPACE = [ \t\r\n];
SPACE = [ \t\r];
ALPHA = [a-zA-Z];
NUM = [0-9];
ALPHANUM = [a-zA-Z0-9_];

@ -111,7 +111,7 @@ size_t unquote(char *dst, const char *str, size_t len)
lpc += 1;
}
else if (str[lpc] == '\\' && (lpc + 1) < len) {
switch (str[lpc] + 1) {
switch (str[lpc + 1]) {
case 'n':
dst[index] = '\n';
break;

@ -125,7 +125,7 @@ public:
break;
case DT_WHITE:
if (this->pp_values.empty() && this->pp_depth == 0) {
this->pp_leading_indent = el.e_capture.length();
// this->pp_leading_indent = el.e_capture.length();
continue;
}
break;
@ -262,7 +262,9 @@ private:
}
void write_element(const element &el) {
if (this->pp_line_length == 0 && el.e_token == DT_WHITE) {
if (this->pp_leading_indent == 0 &&
this->pp_line_length == 0 &&
el.e_token == DT_WHITE) {
return;
}
if (this->pp_line_length == 0 && el.e_token == DT_LINE) {
@ -274,14 +276,33 @@ private:
}
if (el.e_token == DT_QUOTED_STRING) {
pcre_input &pi = this->pp_scanner->get_input();
auto_mem<char> unquoted_str((char *)malloc(pi.pi_length));
auto_mem<char> unquoted_str((char *)malloc(el.e_capture.length() + 1));
const char *start = pi.get_substr_start(&el.e_capture);
unquote(unquoted_str.in(), start, el.e_capture.length());
data_scanner ds(unquoted_str.in());
pretty_printer str_pp(&ds, this->pp_leading_indent);
pretty_printer str_pp(&ds,
this->pp_leading_indent + this->pp_depth * 4);
std::string result = str_pp.print();
if (result.find('\n') != std::string::npos) {
this->pp_stream << str_pp.print();
switch (start[0]) {
case 'r':
case 'u':
this->pp_stream << start[0];
this->pp_stream << start[1] << start[1];
break;
default:
this->pp_stream << start[0] << start[0];
break;
}
this->pp_stream
<< std::endl
<< result;
if (!endswith(result.c_str(), "\n")) {
this->pp_stream << std::endl;
}
this->pp_stream
<< start[el.e_capture.length() - 1]
<< start[el.e_capture.length() - 1];
} else {
this->pp_stream << pi.get_substr(&el.e_capture);
}

@ -538,6 +538,7 @@ run_test ${lnav_test} -n \
-c ":switch-to-view pretty" \
${test_dir}/textfile_quoted_json.0
check_output "pretty-printer is not working for quoted text" <<EOF
''
{
"foo bar": null,
"array": [
@ -550,6 +551,7 @@ check_output "pretty-printer is not working for quoted text" <<EOF
"two": true
}
}
''
EOF
run_test ${lnav_test} -n \
@ -557,7 +559,6 @@ run_test ${lnav_test} -n \
${test_dir}/logfile_vami.0
check_output "pretty-printer is not working" <<EOF
2015-03-12T23:16:52.071:INFO:com.root:Response :
<?xml version="1.0"?>
<response>
<locale>en-US</locale>
@ -611,16 +612,15 @@ Apr 7 00:49:42 Tim-Stacks-iMac kernel[0]: Ethernet [AppleBCM5701Ethernet]: Link
3800
]
Apr 7 05:49:53 Tim-Stacks-iMac.local GoogleSoftwareUpdateDaemon[17212]: -[KSUpdateCheckAction performAction]
KSUpdateCheckAction running KSServerUpdateRequest:
<KSOmahaServerUpdateRequest:0x511f30
server=<KSOmahaServer:0x510d80>
KSUpdateCheckAction running KSServerUpdateRequest: <KSOmahaServerUpdateRequest:0x511f30
server=
<KSOmahaServer:0x510d80>
url="https://tools.google.com/service/update2"
runningFetchers=0
tickets=1
activeTickets=1
rollCallTickets=1
body=
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<o:gupdate xmlns:o="http://www.google.com/update2/request" protocol="2.0" version="KeystoneDaemon-1.2.0.7709" ismachine="1" requestid="{0DFDBCD1-5E29-4DFC-BD99-31A2397198FE}">
<o:os platform="mac" version="MacOSX" sp="10.10.2_x86_64h"></o:os>
@ -629,9 +629,9 @@ Apr 7 05:49:53 Tim-Stacks-iMac.local GoogleSoftwareUpdateDaemon[17212]: -[KSUpd
<o:updatecheck></o:updatecheck>
</o:app>
</o:gupdate>
>
>
Apr 7 07:31:56 Tim-Stacks-iMac.local VirtualBox[36403]: WARNING: The Gestalt selector gestaltSystemVersion is returning 10.9.2 instead of 10.10.2. Use NSProcessInfo's operatingSystemVersion property to get correct system version number.
Call location:
Call location:
Apr 7 07:31:56 Tim-Stacks-iMac.local VirtualBox[36403]: 0 CarbonCore 0x00007fff8a9b3d9b ___Gestalt_SystemVersion_block_invoke + 113
Apr 7 07:31:56 Tim-Stacks-iMac.local VirtualBox[36403]: 1 libdispatch.dylib 0x00007fff8bc84c13 _dispatch_client_callout + 8
Apr 7 07:32:56 Tim-Stacks-iMac.local logger[234]: Bad data {

@ -8,3 +8,30 @@ check_output "pretty print not able to properly grok ipv4?" <<EOF
<foo>8.8.8.8 (google-public-dns-a.google.com)</foo>
9 8.8.8.8 (google-public-dns-a.google.com)<1054 198.51.100.1546 544.9.8.7 98.542.241.99 19143.2.5.6
EOF
cat <<EOF
2015-04-18T13:16:30.003 {"wrapper": {"msg": r"Hello,\nWorld!\n"}}
EOF | run_test ${lnav_test} -n -c ":switch-to-view pretty"
check_output "pretty print is not interpreting quoted strings correctly?" <<EOF
2015-04-18T13:16:30.003 {
"wrapper": {"msg": r""
Hello,
World!
""}}
EOF
cat <<EOF
{"wrapper": [{"message":"\nselect Id from Account where id = $sfid\n ^\nERROR at Row:1:Column:34\nline 1:34 no viable alternative at character '$'"}]}
EOF | run_test ${lnav_test} -n -c ":switch-to-view pretty"
check_output "pretty print is not including leading white space?" <<EOF
{
"wrapper": [
{"message":""
select Id from Account where id = \$sfid
^
ERROR at Row:1:Column:34
line 1:34 no viable alternative at character '\$'
""}]}
EOF

Loading…
Cancel
Save