From 3e8744960320fdb7c60a5932181ea2ca2e330740 Mon Sep 17 00:00:00 2001 From: arrow2nd <44780846+arrow2nd@users.noreply.github.com> Date: Sat, 3 Feb 2024 20:16:56 +0900 Subject: [PATCH] fix: unescaped brackets in path --- langserver/handler.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/langserver/handler.go b/langserver/handler.go index dbdfce0..35a6374 100644 --- a/langserver/handler.go +++ b/langserver/handler.go @@ -692,14 +692,21 @@ func replaceCommandInputFilename(command, fname, rootPath string) string { ext := filepath.Ext(fname) ext = strings.TrimPrefix(ext, ".") - command = strings.Replace(command, "${INPUT}", fname, -1) + command = strings.Replace(command, "${INPUT}", escapeBrackets(fname), -1) command = strings.Replace(command, "${FILEEXT}", ext, -1) - command = strings.Replace(command, "${FILENAME}", filepath.FromSlash(fname), -1) - command = strings.Replace(command, "${ROOT}", rootPath, -1) + command = strings.Replace(command, "${FILENAME}", escapeBrackets(filepath.FromSlash(fname)), -1) + command = strings.Replace(command, "${ROOT}", escapeBrackets(rootPath), -1) return command } +func escapeBrackets(path string) string { + path = strings.Replace(path, "(", `\(`, -1) + path = strings.Replace(path, ")", `\)`, -1) + + return path +} + func succeeded(err error) bool { exitErr, ok := err.(*exec.ExitError) // When the context is canceled, the process is killed,