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.

Normalize line endings in HTTP responses for Windows generated scripts (#5916)

Trevor Manz5cf7424fd788
diff --git a/marimo/_utils/requests.py b/marimo/_utils/requests.py
index 2ddc546568..926a71c990 100644
--- a/marimo/_utils/requests.py
+++ b/marimo/_utils/requests.py
@@ -49,8 +49,14 @@ class Response:
This assumes the response is UTF-8 encoded.
In future, we can infer the encoding from the headers.
+
+ Line endings are normalized to Unix style (\n) to match Python's
+ text mode behavior when reading files.
"""
- return self.content.decode("utf-8")
+ decoded = self.content.decode("utf-8")
+ # Normalize line endings: \r\n -> \n, \r -> \n
+ # This matches Python's universal newline mode used by Path.read_text()
+ return decoded.replace("\r\n", "\n").replace("\r", "\n")
def raise_for_status(self) -> "Response":
"""Raise an exception for non-2xx status codes.
diff --git a/tests/_utils/test_inline_script_metadata.py b/tests/_utils/test_inline_script_metadata.py
index f7ad03f26f..646d14ef1b 100644
--- a/tests/_utils/test_inline_script_metadata.py
+++ b/tests/_utils/test_inline_script_metadata.py
@@ -55,6 +55,43 @@ app = marimo.App(width="medium")
assert PyProjectReader.from_script(SCRIPT).dependencies == []
+def test_windows_line_endings_from_url():
+ """Test that script metadata from URL with Windows line endings is parsed correctly."""
+ from unittest.mock import patch
+
+ from marimo._utils.requests import Response
+
+ # Script content as it would come from a Windows server with CRLF line endings
+ SCRIPT_WITH_CRLF = b"""# /// script\r
+# requires-python = ">=3.11"\r
+# dependencies = [\r
+# "polars",\r
+# "marimo>=0.8.0",\r
+# ]\r
+# ///\r
+\r
+import marimo\r
+\r
+__generated_with = "0.8.2"\r
+app = marimo.App(width="medium")\r
+"""
+
+ url = "https://example.com/notebook.py"
+
+ with patch("marimo._utils.requests.get") as mock_get:
+ # Mock the response to return content with Windows line endings
+ mock_get.return_value = Response(
+ 200,
+ SCRIPT_WITH_CRLF,
+ {},
+ )
+
+ # This should now work correctly with the line ending normalization in response.text()
+ reader = PyProjectReader.from_filename(url)
+ assert reader.dependencies == ["polars", "marimo>=0.8.0"]
+ assert reader.python_version == ">=3.11"
+
+
def test_pyproject_toml_to_requirements_txt_git_sources():
pyproject = {
"dependencies": [