From b1b7af918d638b629978ed71d4dfe72d9c09a036 Mon Sep 17 00:00:00 2001 From: Sreenivasa Pydi Date: Mon, 16 Mar 2026 14:24:25 -0700 Subject: [PATCH 1/2] prevent strings from being misclassified as arrays in variant visitor --- json5_parser/json5_parser_value.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/json5_parser/json5_parser_value.h b/json5_parser/json5_parser_value.h index 6181cea..56b496c 100644 --- a/json5_parser/json5_parser_value.h +++ b/json5_parser/json5_parser_value.h @@ -119,6 +119,8 @@ class Value_impl { class Variant_converter_visitor : public boost::static_visitor { public: + Variant operator()(const String_type& value) const { return value; } + template class Cont> Variant operator()(const Cont& cont) const { return Array(cont.begin(), cont.end()); From 85d2f1063a87c05793b1994ba986d29770e34ac0 Mon Sep 17 00:00:00 2001 From: Sreenivasa Pydi Date: Thu, 26 Mar 2026 15:48:20 -0700 Subject: [PATCH 2/2] resolve compiler warnings, port to Debian 12 --- json5_parser/json5_parser_reader_template.h | 31 +++++++++++++-------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/json5_parser/json5_parser_reader_template.h b/json5_parser/json5_parser_reader_template.h index 865daf7..fa2bbd9 100644 --- a/json5_parser/json5_parser_reader_template.h +++ b/json5_parser/json5_parser_reader_template.h @@ -11,6 +11,7 @@ #endif #include +#include #include #include "json5_parser_error_position.h" @@ -139,28 +140,36 @@ template String_type substitute_esc_chars(typename String_type::const_iterator begin, typename String_type::const_iterator end) { typedef typename String_type::const_iterator Iter_type; - - if (end - begin < 2) return String_type(begin, end); - String_type result; - result.reserve(end - begin); + if (begin == end) return result; - const Iter_type end_minus_1(end - 1); + result.reserve(static_cast(std::distance(begin, end))); Iter_type substr_start = begin; Iter_type i = begin; - for (; i < end_minus_1; ++i) { - if (*i == '\\') { - result.append(substr_start, i); + while (i != end) { + if (*i != '\\') { + ++i; + continue; + } - ++i; // skip the '\' + result.append(substr_start, i); - append_esc_char_and_incr_iter(result, i, end); + ++i; // skip the '\\' - substr_start = i + 1; + // Preserve a trailing backslash literally. + if (i == end) { + result += '\\'; + substr_start = end; + break; } + + append_esc_char_and_incr_iter(result, i, end); + + ++i; + substr_start = i; } result.append(substr_start, end);