You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(replace_regex): handle escape sequences for newlines
A robust fix was implemented for the `replace_regex` tool to handle escape sequences correctly, which resolves the issue of newline characters being interpreted as literals. Documentation was added to explain the nature of the problem and the solution. All tests now pass, confirming that the implementation works as intended.
The `replace_regex` tool was causing syntax errors when processing strings containing newline escape sequences (`\n`). Instead of properly handling these escape sequences, the tool was inserting literal newlines into the code, breaking the syntax of string literals, particularly f-strings. This resulted in errors like:
6
+
7
+
```
8
+
print(f'
9
+
^
10
+
SyntaxError: unterminated f-string literal
11
+
```
12
+
13
+
The issue was reported by multiple users across different operating systems (Windows, macOS, Linux), suggesting it was not platform-specific. The common factor was strings with newline escape sequences.
14
+
15
+
## Root Cause Analysis
16
+
17
+
After extensive testing, we identified that the issue occurred specifically when the replacement string contained a literal newline character rather than an escaped newline sequence. When such a string was passed to the `ReplaceRegexTool.apply` method, the literal newline was not being properly escaped, resulting in it being inserted directly into the output file.
18
+
19
+
This was particularly problematic for string literals, as it would break them across multiple lines, causing syntax errors.
20
+
21
+
## Solution
22
+
23
+
We implemented a two-step approach to fix the issue:
24
+
25
+
1.**Pre-process the replacement string** to explicitly replace any literal newlines with escaped newlines:
0 commit comments