Fix Windows C# JSON parsing errors by normalizing paths

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 <noreply@anthropic.com>
This commit is contained in:
Michael PanchenkoandClaude committed 2025-06-29 01:38:16 +02:00
1 parent 0ea317bd33
commit a8b54077fe
1 file changed
+11 -2
+11 -2
View File
@@ -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