From a8b54077fe2d7628dcc8550415a8f7825053acb1 Mon Sep 17 00:00:00 2001 From: Michael Panchenko Date: Sun, 29 Jun 2025 01:38:16 +0200 Subject: [PATCH] Fix Windows C# JSON parsing errors by normalizing paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Normalize all paths to use forward slashes instead of backslashes to prevent JSON parsing errors when Windows paths contain unescaped backslashes. This affects PathUtils.uri_to_path() and PathUtils.get_relative_path(). Fixes JSONDecodeError: Invalid \escape and Expecting value errors in C# tests on Windows. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/solidlsp/ls_utils.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/solidlsp/ls_utils.py b/src/solidlsp/ls_utils.py index 7aa610ed..f41f089b 100644 --- a/src/solidlsp/ls_utils.py +++ b/src/solidlsp/ls_utils.py @@ -131,7 +131,13 @@ class PathUtils: from urlparse import urlparse parsed = urlparse(uri) host = f"{os.path.sep}{os.path.sep}{parsed.netloc}{os.path.sep}" - return os.path.normpath(os.path.join(host, url2pathname(unquote(parsed.path)))) + path = os.path.normpath(os.path.join(host, url2pathname(unquote(parsed.path)))) + + # Normalize backslashes to forward slashes for JSON compatibility + # This prevents JSON parsing errors when paths contain unescaped backslashes + path = path.replace("\\", "/") + + return path @staticmethod def path_to_uri(path: str) -> str: @@ -152,7 +158,10 @@ class PathUtils: returns `None` otherwise. """ if PurePath(path).drive == PurePath(base_path).drive: - return str(PurePath(os.path.relpath(path, base_path))) + rel_path = str(PurePath(os.path.relpath(path, base_path))) + # Normalize backslashes to forward slashes for JSON compatibility + rel_path = rel_path.replace("\\", "/") + return rel_path return None