fix that backslashes in commit messages were not escaped in the JSON v1.1.2

Tue, 16 Dec 2025 21:23:17 +0100

author
Mike Becker <universe@uap-core.de>
date
Tue, 16 Dec 2025 21:23:17 +0100
changeset 71
39644afa3808
parent 70
a629b831c96d
child 72
93de83b09c2d

fix that backslashes in commit messages were not escaped in the JSON

resolves #788

CHANGELOG file | annotate | diff | comparison | revisions
Makefile file | annotate | diff | comparison | revisions
src/html.cpp file | annotate | diff | comparison | revisions
src/main.cpp file | annotate | diff | comparison | revisions
--- a/CHANGELOG	Sun Nov 30 22:55:34 2025 +0100
+++ b/CHANGELOG	Tue Dec 16 21:23:17 2025 +0100
@@ -1,3 +1,7 @@
+Version 1.1.2 - 2025-12-15
+
+- Fix that backslashes in commit messages were not escaped in the JSON
+
 Version 1.1.1 - 2025-10-09
 
 - Fix that only the main branch was considered in git repositories
--- a/Makefile	Sun Nov 30 22:55:34 2025 +0100
+++ b/Makefile	Tue Dec 16 21:23:17 2025 +0100
@@ -21,7 +21,7 @@
 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-VERSION=1.1.1
+VERSION=1.1.2
 
 all: compile FORCE
 
--- a/src/html.cpp	Sun Nov 30 22:55:34 2025 +0100
+++ b/src/html.cpp	Tue Dec 16 21:23:17 2025 +0100
@@ -394,15 +394,19 @@
         static_cast<unsigned>(ymd.day()));
 
     // Utility function to escape strings in JSON
-    auto escape_json = [](std::string str) static {
-        size_t pos = str.find('\"');
-        if (pos == std::string::npos) return str;
-        std::string escaped = std::move(str);
-        do {
-            escaped.replace(pos, 1, "\\\"");
-            pos += 2;
-        } while ((pos = escaped.find('\"', pos)) != std::string::npos);
-        return escaped;
+    auto escape_json = [](std::string raw) static {
+        using std::string_view_literals::operator ""sv;
+        auto replace_all = [](std::string str, char chr, std::string_view repl) static {
+            size_t pos = str.find(chr);
+            if (pos == std::string::npos) return str;
+            std::string result = std::move(str);
+            do {
+                result.replace(pos, 1, repl);
+                pos += repl.length();
+            } while ((pos = result.find(chr, pos)) != std::string::npos);
+            return result;
+        };
+        return replace_all(replace_all(std::move(raw), '\\', "\\\\"), '\"', "\\\""sv);
     };
 
     // Build a JSON object of commit summaries
--- a/src/main.cpp	Sun Nov 30 22:55:34 2025 +0100
+++ b/src/main.cpp	Tue Dec 16 21:23:17 2025 +0100
@@ -38,7 +38,7 @@
 
 using namespace std::chrono;
 
-static constexpr auto program_version = "1.1.1";
+static constexpr auto program_version = "1.1.2";
 
 static void print_help() {
     fputs(

mercurial