Skip to content

Reverse-engineer any video, shot by shot: filmed, AI-generated or coded, and how to remake it. Breakdowns in the open VIDEO.md format. 逆向一切视频,逐个镜头看是拍的、AI 生成的还是代码做的,再告诉你怎么复刻;拆解结果按 VIDEO.md 格式输出。

load_env_files: ignore a comment after the value

heojunfofbf9904b578e
diff --git a/rea_video/util.py b/rea_video/util.py
index f048345..27ca417 100644
--- a/rea_video/util.py
+++ b/rea_video/util.py
@@ -4,6 +4,7 @@ from __future__ import annotations
import json
import logging
import os
+import re
import sys
from pathlib import Path
from typing import Any, Iterable
@@ -212,8 +213,20 @@ def sha256_file(path: Path) -> str:
return h.hexdigest()
+_ENV_QUOTED = re.compile(r"""((["']).*?\2)\s*(?:#.*)?""")
+
+
+def _env_value(raw: str) -> str:
+ """The value of a KEY=VALUE line, read the way dotenv files usually are: a quoted value ends at its closing
+ quote and a comment after it is dropped; unquoted, a comment starts at a # that follows whitespace, so
+ pa#ss and http://x/#frag stay whole."""
+ quoted = _ENV_QUOTED.fullmatch(raw.strip())
+ value = quoted.group(1) if quoted else re.sub(r"\s#.*", "", raw).strip()
+ return value.strip('"').strip("'")
+
+
def load_env_files(paths: Iterable[str | Path]) -> list[str]:
- """Minimal .env loader (KEY=VALUE lines). Existing env vars win. Returns loaded files."""
+ """Minimal .env loader (KEY=VALUE lines, `# comment` after a value allowed). Existing env vars win. Returns loaded files."""
loaded: list[str] = []
for raw in paths:
if not raw:
@@ -229,9 +242,8 @@ def load_env_files(paths: Iterable[str | Path]) -> list[str]:
line = line[len("export "):]
key, _, value = line.partition("=")
key = key.strip()
- value = value.strip().strip('"').strip("'")
if key and key not in os.environ:
- os.environ[key] = value
+ os.environ[key] = _env_value(value)
loaded.append(str(p))
return loaded