From e4e10fb74637f642a616a020751ffac74e5c5370 Mon Sep 17 00:00:00 2001 From: "Vitalii Serhiiovych Horbatov -X (vhorbato - SOFTSERVE INC at Cisco)" Date: Wed, 4 Jun 2025 07:10:57 +0000 Subject: [PATCH] Pull request #4766: helpers: fix JSON stream flags ater escaping Merge in SNORT/snort3 from ~VHORBATO/snort3:json_escape_ios to master Squashed commit of the following: commit 4eb098766a157f0572e55be1195693ccea139df7 Author: vhorbato Date: Fri May 30 18:49:37 2025 +0300 helpers: fix JSON stream flags after escaping --- src/helpers/json_stream.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/helpers/json_stream.cc b/src/helpers/json_stream.cc index bcc3c6e06..aff990182 100644 --- a/src/helpers/json_stream.cc +++ b/src/helpers/json_stream.cc @@ -210,7 +210,10 @@ void JsonStream::put_escaped(const char* v, size_t len) { out.write(buf, dst - buf); dst = buf; + + std::ios_base::fmtflags flags = out.flags(); out << "\\u" << std::hex << std::setw(4) << std::setfill('0') << (0xFF & c); + out.flags(flags); } } } @@ -235,8 +238,15 @@ public: void check_escaping(const char* f, const char* input, size_t i_len, const std::string& expected) { oss.str(std::string()); + auto flags_before = oss.flags(); + auto precision_before = oss.precision(); + auto width_before = oss.width(); + put(f, std::string(input, i_len)); CHECK(oss.str() == expected); + CHECK(oss.flags() == flags_before); + CHECK(oss.precision() == precision_before); + CHECK(oss.width() == width_before); } private: -- 2.47.3