diff --git a/pkgs/clan-cli/clan_cli/api/serde.py b/pkgs/clan-cli/clan_cli/api/serde.py index e3ef28be5..04c6ae2d5 100644 --- a/pkgs/clan-cli/clan_cli/api/serde.py +++ b/pkgs/clan-cli/clan_cli/api/serde.py @@ -30,7 +30,6 @@ Note: This module assumes the presence of other modules and classes such as `Cla """ import dataclasses -import json from dataclasses import dataclass, fields, is_dataclass from enum import Enum from pathlib import Path @@ -162,7 +161,7 @@ def construct_value( msg = f"Expected string, got {field_value}" raise ClanError(msg, location=f"{loc}") - return json.loads(f'"{field_value}"') + return field_value if t is int and not isinstance(field_value, str): return int(field_value) # type: ignore diff --git a/pkgs/clan-cli/tests/test_deserializers.py b/pkgs/clan-cli/tests/test_deserializers.py index 7b0e64233..ecbbfa06a 100644 --- a/pkgs/clan-cli/tests/test_deserializers.py +++ b/pkgs/clan-cli/tests/test_deserializers.py @@ -217,8 +217,8 @@ def test_none_or_string() -> None: def test_roundtrip_escape() -> None: - assert from_dict(str, "\\n") == "\n" - assert dataclass_to_dict("\n") == "\\n" + assert from_dict(str, "\n") == "\n" + assert dataclass_to_dict("\n") == "\n" # Test that the functions are inverses of each other # f(g(x)) == x diff --git a/pkgs/clan-cli/tests/test_serializers.py b/pkgs/clan-cli/tests/test_serializers.py index c0ce5b3a9..927c71ac7 100644 --- a/pkgs/clan-cli/tests/test_serializers.py +++ b/pkgs/clan-cli/tests/test_serializers.py @@ -11,27 +11,25 @@ from clan_cli.api import ( def test_sanitize_string() -> None: # Simple strings assert sanitize_string("Hello World") == "Hello World" - assert sanitize_string("Hello\nWorld") == "Hello\\nWorld" - assert sanitize_string("Hello\tWorld") == "Hello\\tWorld" - assert sanitize_string("Hello\rWorld") == "Hello\\rWorld" - assert sanitize_string("Hello\fWorld") == "Hello\\fWorld" - assert sanitize_string("Hello\vWorld") == "Hello\\u000bWorld" - assert sanitize_string("Hello\bWorld") == "Hello\\bWorld" - assert sanitize_string("Hello\\World") == "Hello\\\\World" - assert sanitize_string('Hello"World') == 'Hello\\"World' + assert sanitize_string("Hello\nWorld") == "Hello\nWorld" + assert sanitize_string("Hello\tWorld") == "Hello\tWorld" + assert sanitize_string("Hello\rWorld") == "Hello\rWorld" + assert sanitize_string("Hello\fWorld") == "Hello\fWorld" + assert sanitize_string("Hello\vWorld") == "Hello\u000bWorld" + assert sanitize_string("Hello\bWorld") == "Hello\bWorld" + assert sanitize_string("Hello\\World") == "Hello\\World" + assert sanitize_string('Hello"World') == 'Hello"World' assert sanitize_string("Hello'World") == "Hello'World" - assert sanitize_string("Hello\0World") == "Hello\\u0000World" + assert sanitize_string("Hello\0World") == "Hello\x00World" # Console escape characters - assert sanitize_string("\033[1mBold\033[0m") == "\\u001b[1mBold\\u001b[0m" # Red - assert sanitize_string("\033[31mRed\033[0m") == "\\u001b[31mRed\\u001b[0m" # Blue - assert ( - sanitize_string("\033[42mGreen\033[0m") == "\\u001b[42mGreen\\u001b[0m" - ) # Green - assert sanitize_string("\033[4mUnderline\033[0m") == "\\u001b[4mUnderline\\u001b[0m" + assert sanitize_string("\033[1mBold\033[0m") == "\033[1mBold\033[0m" # Red + assert sanitize_string("\033[31mRed\033[0m") == "\033[31mRed\033[0m" # Blue + assert sanitize_string("\033[42mGreen\033[0m") == "\033[42mGreen\033[0m" # Green + assert sanitize_string("\033[4mUnderline\033[0m") == "\033[4mUnderline\033[0m" assert ( sanitize_string("\033[91m\033[1mBold Red\033[0m") - == "\\u001b[91m\\u001b[1mBold Red\\u001b[0m" + == "\033[91m\033[1mBold Red\033[0m" )