]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #4766: helpers: fix JSON stream flags ater escaping
authorVitalii Serhiiovych Horbatov -X (vhorbato - SOFTSERVE INC at Cisco) <vhorbato@cisco.com>
Wed, 4 Jun 2025 07:10:57 +0000 (07:10 +0000)
committerOleksii Shumeiko -X (oshumeik - SOFTSERVE INC at Cisco) <oshumeik@cisco.com>
Wed, 4 Jun 2025 07:10:57 +0000 (07:10 +0000)
Merge in SNORT/snort3 from ~VHORBATO/snort3:json_escape_ios to master

Squashed commit of the following:

commit 4eb098766a157f0572e55be1195693ccea139df7
Author: vhorbato <vhorbato@cisco.com>
Date:   Fri May 30 18:49:37 2025 +0300

    helpers: fix JSON stream flags after escaping

src/helpers/json_stream.cc

index bcc3c6e06614aba74b15a9c863c79ee545a04d90..aff9901825bdad5971b18ebbf86aa5bcf45d3abc 100644 (file)
@@ -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: