From e0d9bfac92d146e7105a151b7eb244add202066a Mon Sep 17 00:00:00 2001 From: baliasnyifeliks Date: Tue, 3 Feb 2026 20:11:25 +0200 Subject: [PATCH] fix: Correct bracket depth calculation by ignoring characters within string literals. --- Makhno/MakhnoInvoke.cs | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/Makhno/MakhnoInvoke.cs b/Makhno/MakhnoInvoke.cs index 6393e88..985631d 100644 --- a/Makhno/MakhnoInvoke.cs +++ b/Makhno/MakhnoInvoke.cs @@ -418,12 +418,51 @@ namespace Makhno return null; int depth = 0; + bool inString = false; + bool escape = false; + char quoteChar = '\0'; + for (int i = startIndex; i < text.Length; i++) { char ch = text[i]; + + if (inString) + { + if (escape) + { + escape = false; + continue; + } + + if (ch == '\\') + { + escape = true; + continue; + } + + if (ch == quoteChar) + { + inString = false; + quoteChar = '\0'; + } + + continue; + } + + if (ch == '"' || ch == '\'') + { + inString = true; + quoteChar = ch; + continue; + } + if (ch == '[') + { depth++; - else if (ch == ']') + continue; + } + + if (ch == ']') { depth--; if (depth == 0)