mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-07-05 15:46:47 -07:00
Fix dollar sign replacement bug in file editing (#7871)
Co-authored-by: Jacob Richman <jacob314@gmail.com>
This commit is contained in:
@@ -4,6 +4,27 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Safely replaces text with literal strings, avoiding ECMAScript GetSubstitution issues.
|
||||
* Escapes $ characters to prevent template interpretation.
|
||||
*/
|
||||
export function safeLiteralReplace(
|
||||
str: string,
|
||||
oldString: string,
|
||||
newString: string,
|
||||
): string {
|
||||
if (oldString === '' || !str.includes(oldString)) {
|
||||
return str;
|
||||
}
|
||||
|
||||
if (!newString.includes('$')) {
|
||||
return str.replaceAll(oldString, newString);
|
||||
}
|
||||
|
||||
const escapedNewString = newString.replaceAll('$', '$$$$');
|
||||
return str.replaceAll(oldString, escapedNewString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a Buffer is likely binary by testing for the presence of a NULL byte.
|
||||
* The presence of a NULL byte is a strong indicator that the data is not plain text.
|
||||
|
||||
Reference in New Issue
Block a user