From e51245851f5d17efdb9fa511357e1ec1a8d9f983 Mon Sep 17 00:00:00 2001 From: Alde Rojas Date: Wed, 24 Dec 2025 10:01:08 -0600 Subject: [PATCH 1/3] replace std::regex_replace when stripping leading space --- include/minja/minja.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/minja/minja.hpp b/include/minja/minja.hpp index 6ed6eda..62b78dd 100644 --- a/include/minja/minja.hpp +++ b/include/minja/minja.hpp @@ -2611,8 +2611,7 @@ class Parser { } } if (pre_space == SpaceHandling::Strip) { - static std::regex leading_space_regex(R"(^\s+)"); - text = std::regex_replace(text, leading_space_regex, ""); + text.erase(0, text.find_first_not_of(" \t\n\r\f\v")); } else if (options.trim_blocks && (it - 1) != begin && !dynamic_cast((*(it - 2)).get())) { if (!text.empty() && text[0] == '\n') { text.erase(0, 1); From 63fab79589fa6a1127a11060ee4eb19b76d0bfd9 Mon Sep 17 00:00:00 2001 From: Alde Rojas Date: Wed, 24 Dec 2025 10:19:31 -0600 Subject: [PATCH 2/3] replace std::regex_replace for trailing space --- include/minja/minja.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/minja/minja.hpp b/include/minja/minja.hpp index 62b78dd..943e290 100644 --- a/include/minja/minja.hpp +++ b/include/minja/minja.hpp @@ -2601,8 +2601,8 @@ class Parser { auto text = text_token->text; if (post_space == SpaceHandling::Strip) { - static std::regex trailing_space_regex(R"(\s+$)"); - text = std::regex_replace(text, trailing_space_regex, ""); + auto pos = text.find_last_not_of(" \t\n\r\f\v"); + text.resize(pos == std::string::npos ? 0 : pos + 1); } else if (options.lstrip_blocks && it != end) { auto i = text.size(); while (i > 0 && (text[i - 1] == ' ' || text[i - 1] == '\t')) i--; From 8d6d80375c38d3711dd8bd6238c3c55362f4e33e Mon Sep 17 00:00:00 2001 From: Alde Rojas Date: Wed, 24 Dec 2025 10:36:57 -0600 Subject: [PATCH 3/3] remove Windows workarounds in test-supported-template --- tests/test-supported-template.cpp | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/tests/test-supported-template.cpp b/tests/test-supported-template.cpp index 52a9615..88a9bbb 100644 --- a/tests/test-supported-template.cpp +++ b/tests/test-supported-template.cpp @@ -43,16 +43,6 @@ static void assert_equals(const T &expected, const T &actual){ } } -#ifdef _WIN32 -// Workaround for https://github.com/ochafik/minja/issues/16 -// On Windows, C++ minja outputs fewer newlines than Python Jinja2 for certain templates. -// This function collapses consecutive blank lines to normalize comparison. -static std::string collapse_blank_lines(const std::string &s) { - static const std::regex blank_lines_regex("\n\n+"); - return std::regex_replace(s, blank_lines_regex, "\n"); -} -#endif - static std::string read_file(const std::string &path) { std::ifstream fs(path, std::ios_base::binary); if (!fs.is_open()) { @@ -162,21 +152,12 @@ int main(int argc, char *argv[]) { return 1; } -#ifdef _WIN32 - // On Windows, collapse blank lines for comparison due to known whitespace handling issues - auto expected_cmp = collapse_blank_lines(expected); - auto actual_cmp = collapse_blank_lines(actual); -#else - auto expected_cmp = expected; - auto actual_cmp = actual; -#endif - - if (expected_cmp != actual_cmp) { + if (expected != actual) { if (getenv("WRITE_GOLDENS")) { write_file(golden_file, actual); std::cerr << "Updated golden file: " << golden_file << "\n"; } else { - assert_equals(expected_cmp, actual_cmp); + assert_equals(expected, actual); } }