mirror of
https://github.com/tstack/lnav.git
synced 2024-08-17 00:40:30 +03:00
[regexp_vtab] hex floats were being passed through to json, which does not support hex floats
It looks like sscanf("%f") was accepting hex-floats. So, lnav was passing that through to the JSON, which does not like hex floats. FYI, @trantor, this should fix the regexp_capture_into_json() issue of hex numbers being passed through.
This commit is contained in:
parent
84d2f56189
commit
c9ec288853
@ -35,6 +35,7 @@
|
||||
#include "column_namer.hh"
|
||||
#include "config.h"
|
||||
#include "pcrepp/pcrepp.hh"
|
||||
#include "scn/scn.h"
|
||||
#include "sql_help.hh"
|
||||
#include "sql_util.hh"
|
||||
#include "vtab_module.hh"
|
||||
@ -332,31 +333,27 @@ CREATE TABLE regexp_capture_into_json (
|
||||
if (!cap->is_valid()) {
|
||||
yajl_gen_null(gen);
|
||||
} else {
|
||||
auto* cap_start = vc.c_input->get_substr_start(cap);
|
||||
char* cap_copy = (char*) alloca(cap->length() + 1);
|
||||
long long int i_value;
|
||||
double d_value;
|
||||
int end_index;
|
||||
auto cap_view = vc.c_input->to_string_view(cap);
|
||||
auto scan_int_res
|
||||
= scn::scan_value<int64_t>(cap_view);
|
||||
|
||||
memcpy(cap_copy, cap_start, cap->length());
|
||||
cap_copy[cap->length()] = '\0';
|
||||
|
||||
if (sscanf(cap_copy, "%lld%n", &i_value, &end_index)
|
||||
== 1
|
||||
&& (end_index == cap->length()))
|
||||
{
|
||||
yajl_gen_integer(gen, i_value);
|
||||
} else if (sscanf(cap_copy,
|
||||
"%lf%n",
|
||||
&d_value,
|
||||
&end_index)
|
||||
== 1
|
||||
&& (end_index == cap->length()))
|
||||
{
|
||||
yajl_gen_number(gen, cap_start, cap->length());
|
||||
} else {
|
||||
yajl_gen_pstring(gen, cap_start, cap->length());
|
||||
if (scan_int_res && scan_int_res.range().empty()) {
|
||||
yajl_gen_integer(gen, scan_int_res.value());
|
||||
continue;
|
||||
}
|
||||
|
||||
auto scan_float_res
|
||||
= scn::scan_value<double>(cap_view);
|
||||
if (scan_float_res
|
||||
&& scan_float_res.range().empty())
|
||||
{
|
||||
yajl_gen_number(
|
||||
gen, cap_view.data(), cap_view.length());
|
||||
continue;
|
||||
}
|
||||
|
||||
yajl_gen_pstring(
|
||||
gen, cap_view.data(), cap_view.length());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -754,8 +754,12 @@ EXPECTED_FILES = \
|
||||
$(srcdir)/%reldir%/test_sql_json_func.sh_f34205b59e04f261897ad89f659595c743a18ca9.out \
|
||||
$(srcdir)/%reldir%/test_sql_json_func.sh_f34f5dfa938a1ac7721f924beb16bbceec127a1b.err \
|
||||
$(srcdir)/%reldir%/test_sql_json_func.sh_f34f5dfa938a1ac7721f924beb16bbceec127a1b.out \
|
||||
$(srcdir)/%reldir%/test_sql_regexp.sh_51293df041b6969ccecc60204dce3676d0fb006d.err \
|
||||
$(srcdir)/%reldir%/test_sql_regexp.sh_51293df041b6969ccecc60204dce3676d0fb006d.out \
|
||||
$(srcdir)/%reldir%/test_sql_regexp.sh_b841a0c09601e2419eeb99e85f7e286c889e4801.err \
|
||||
$(srcdir)/%reldir%/test_sql_regexp.sh_b841a0c09601e2419eeb99e85f7e286c889e4801.out \
|
||||
$(srcdir)/%reldir%/test_sql_regexp.sh_bbd1128cf61a9af8f9dc937b46217443f42e1a7a.err \
|
||||
$(srcdir)/%reldir%/test_sql_regexp.sh_bbd1128cf61a9af8f9dc937b46217443f42e1a7a.out \
|
||||
$(srcdir)/%reldir%/test_sql_search_table.sh_1a0d872ebc492fcecb2e79a0993170d5fc771a5b.err \
|
||||
$(srcdir)/%reldir%/test_sql_search_table.sh_1a0d872ebc492fcecb2e79a0993170d5fc771a5b.out \
|
||||
$(srcdir)/%reldir%/test_sql_search_table.sh_3f5f74863d065418bca5a000e6ad3d9344635164.err \
|
||||
|
@ -0,0 +1,2 @@
|
||||
[1m[4mmatch_index [0m[1m[4m content [0m
|
||||
[1m[7m 0[0m[1m[7m [0m[1m[7m{"key":"foo","value":4670}[0m[1m [0m
|
@ -0,0 +1,2 @@
|
||||
[1m[4mmatch_index [0m[1m[4m content [0m
|
||||
[1m 0[0m[1m [0m[1m{"key":"foo","value":"123e"} [0m
|
@ -6,3 +6,11 @@ run_cap_test ${lnav_test} -n \
|
||||
-c ";SELECT * FROM syslog_log, regexp_capture_into_json(log_body, '"'"'"(?<value>[^"'"'"]+)')" \
|
||||
-c ":write-csv-to -" \
|
||||
${test_dir}/logfile_syslog.3
|
||||
|
||||
run_cap_test ${lnav_test} -n \
|
||||
-c ";SELECT * from regexp_capture_into_json('foo=0x123e;', '(?<key>\w+)=(?<value>[^;]+)')" \
|
||||
${test_dir}/logfile_syslog.3
|
||||
|
||||
run_cap_test ${lnav_test} -n \
|
||||
-c ";SELECT * from regexp_capture_into_json('foo=123e;', '(?<key>\w+)=(?<value>[^;]+)')" \
|
||||
${test_dir}/logfile_syslog.3
|
||||
|
Loading…
Reference in New Issue
Block a user