In bifs, change ODesc objects to have RAW_STYLE.

This prevents double-escaping with the logging changes of BIT-1333.
This commit is contained in:
Robin Sommer 2015-04-16 20:40:47 -07:00
parent 7344052b50
commit 7225221c2a
6 changed files with 23 additions and 5 deletions

@ -1 +1 @@
Subproject commit 1a2ab9ee7c80ca905e86a2a11283e7c0477341a9
Subproject commit a5f4bd828662f3a9f4050747dfca4fb216bdb443

View file

@ -128,6 +128,7 @@ static void do_fmt(const char*& fmt, Val* v, ODesc* d)
char out_buf[512];
ODesc s;
s.SetStyle(RAW_STYLE);
if ( precision >= 0 && *fmt != 'e' && *fmt != 'f' && *fmt != 'g' )
builtin_error("precision specified for non-floating point");
@ -250,12 +251,12 @@ static void do_fmt(const char*& fmt, Val* v, ODesc* d)
d->Add(" ");
}
d->Add(s.Description());
d->AddN((const char*)(s.Bytes()), s.Len());
// Right-padding with whitespace, if any.
if ( field_width > 0 && left_just )
{
int sl = strlen(s.Description());
int sl = s.Len();
while ( ++sl <= field_width )
d->Add(" ");
}
@ -1342,6 +1343,8 @@ function order%(v: any, ...%) : index_vec
function cat%(...%): string
%{
ODesc d;
d.SetStyle(RAW_STYLE);
loop_over_list(@ARG@, i)
@ARG@[i]->Describe(&d);
@ -1367,6 +1370,8 @@ function cat%(...%): string
function cat_sep%(sep: string, def: string, ...%): string
%{
ODesc d;
d.SetStyle(RAW_STYLE);
int pre_size = 0;
loop_over_list(@ARG@, i)
@ -1443,6 +1448,8 @@ function fmt%(...%): string
const char* fmt = fmt_v->AsString()->CheckString();
ODesc d;
d.SetStyle(RAW_STYLE);
int n = 0;
while ( next_fmt(fmt, @ARGS@, &d, n) )

View file

@ -207,6 +207,8 @@ function join_string_array%(sep: string, a: string_array%): string &deprecated
function join_string_vec%(vec: string_vec, sep: string%): string
%{
ODesc d;
d.SetStyle(RAW_STYLE);
VectorVal *v = vec->AsVectorVal();
for ( unsigned i = 0; i < v->Size(); ++i )

View file

@ -4,6 +4,8 @@ AB\xffCD\x00
abc\x00def
abc\x00def
foo \xc2\xae bar \xc2\xae baz
foo\x00bar\0baz
foo \x0e bar ^N baz

View file

@ -3,7 +3,7 @@
#empty_field (empty)
#unset_field -
#path test
#open 2015-04-15-23-47-40
#open 2015-04-17-03-37-33
#fields s
#types string
AB\x00CD\x00
@ -12,7 +12,9 @@ AB\\xffCD\x00
abc\\x00def
abc\x00def
foo \xc2\xae bar \\xc2\\xae baz
foo\x00bar\\0baz
foo \x0e bar ^N baz
#close 2015-04-15-23-47-40
#close 2015-04-17-03-37-33

View file

@ -16,6 +16,7 @@ event bro_init()
{
local a = "abc\0def";
local b = escape_string(a);
local c = fmt("%s", a);
Log::create_stream(Test::LOG, [$columns=Log]);
Log::write(Test::LOG, [$s="AB\0CD\0"]);
@ -24,6 +25,8 @@ event bro_init()
Log::write(Test::LOG, [$s=" "]);
Log::write(Test::LOG, [$s=b]);
Log::write(Test::LOG, [$s=" "]);
Log::write(Test::LOG, [$s=c]);
Log::write(Test::LOG, [$s=" "]);
Log::write(Test::LOG, [$s="foo \xc2\xae bar \\xc2\\xae baz"]);
Log::write(Test::LOG, [$s="foo\x00bar\\0baz"]);
Log::write(Test::LOG, [$s="foo \16 bar ^N baz"]);
@ -34,6 +37,8 @@ event bro_init()
print "";
print b;
print "";
print c;
print "";
print "foo \xc2\xae bar \\xc2\\xae baz";
print "foo\x00bar\\0baz";
print "foo \16 bar ^N baz";