zeek/testing/btest/scripts/base/frameworks/logging/ascii-escape-binary.bro
Robin Sommer 7344052b50 Changing what's escaped when printing.
With this patch the model is:

    - "print" cleans the data so that non-printable characters get
      escaped. This is not necessarily reversible.

    - to print in a reversible way, one can go through
      escape_string(); this escapes backslashes as well to make the
      decoding non-ambigious.

    - Logging always escapes similar to escape_string(), making it
      reversible.

Compared to master, we also change the escaping as follows:

    - We now only escape with "\xXX", no more "^X" or "\0". Exception:
      backslashes.

    - We escape backlashes as "\\".

    - There's no "alternative" output style anymore, i.e., fmt() '%A'
      qualifier is gone.

Baselines in testing/btest are updated, external tests not yet.

Addresses BIT-1333.
2015-04-15 16:59:50 -07:00

43 lines
924 B
Text

# @TEST-EXEC: bro -b %INPUT >output
# @TEST-EXEC: btest-diff test.log
# @TEST-EXEC: btest-diff output
module Test;
export {
redef enum Log::ID += { LOG };
type Log: record {
s: string;
} &log;
}
event bro_init()
{
local a = "abc\0def";
local b = escape_string(a);
Log::create_stream(Test::LOG, [$columns=Log]);
Log::write(Test::LOG, [$s="AB\0CD\0"]);
Log::write(Test::LOG, [$s="AB\xffCD\0"]);
Log::write(Test::LOG, [$s="AB\\xffCD\0"]);
Log::write(Test::LOG, [$s=" "]);
Log::write(Test::LOG, [$s=b]);
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"]);
print "AB\0CD\0";
print "AB\xffCD\0";
print "AB\\xffCD\0";
print "";
print b;
print "";
print "foo \xc2\xae bar \\xc2\\xae baz";
print "foo\x00bar\\0baz";
print "foo \16 bar ^N baz";
print "";
}