Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: allow backslashes in app config (file format) (#2209)

Akshay Agrawal1e6a8b292c5b
diff --git a/marimo/_ast/codegen.py b/marimo/_ast/codegen.py
index 79cd43fe59..ea92d0a91a 100644
--- a/marimo/_ast/codegen.py
+++ b/marimo/_ast/codegen.py
@@ -124,7 +124,7 @@ def generate_unparsable_cell(
def generate_app_constructor(config: Optional[_AppConfig]) -> str:
def _format_arg(arg: Any) -> str:
if isinstance(arg, str):
- return f'"{arg}"'
+ return f'"{arg}"'.replace("\\", "\\\\")
else:
return str(arg)
diff --git a/tests/_ast/codegen_data/test_generate_filecontents_empty_with_config.py b/tests/_ast/codegen_data/test_generate_filecontents_empty_with_config.py
index 627f51c608..9d9a1dc88f 100644
--- a/tests/_ast/codegen_data/test_generate_filecontents_empty_with_config.py
+++ b/tests/_ast/codegen_data/test_generate_filecontents_empty_with_config.py
@@ -1,7 +1,7 @@
import marimo
__generated_with = "0.4.6"
-app = marimo.App(width="full", app_title="test_title")
+app = marimo.App(width="full", app_title="test_title", css_file="a\\b.css")
diff --git a/tests/_ast/test_codegen.py b/tests/_ast/test_codegen.py
index c970a03789..10c85ead18 100644
--- a/tests/_ast/test_codegen.py
+++ b/tests/_ast/test_codegen.py
@@ -71,7 +71,9 @@ class TestGeneration:
@staticmethod
def test_generate_filecontents_empty_with_config() -> None:
- config = _AppConfig(app_title="test_title", width="full")
+ config = _AppConfig(
+ app_title="test_title", width="full", css_file=r"a\b.css"
+ )
contents = wrap_generate_filecontents([], [], config=config)
assert contents == get_expected_filecontents(
"test_generate_filecontents_empty_with_config"