Skip to content

Commit

Permalink
Sanitize debug log file names to avoid crashing (#670)
Browse files Browse the repository at this point in the history
* Sanitize debug log file names to avoid crashing

* Bump version

* Fix test
  • Loading branch information
mars-lan authored Nov 7, 2023
1 parent 2623cfd commit 90b6093
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 37 deletions.
6 changes: 5 additions & 1 deletion metaphor/common/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import tempfile
from typing import Any

from pathvalidate import sanitize_filename

_, LOG_FILE = tempfile.mkstemp(suffix=".log")

formatter = logging.Formatter(
Expand Down Expand Up @@ -35,7 +37,9 @@ def add_debug_file(file: str) -> None:


def json_dump_to_debug_file(value: Any, file_name: str) -> str:
out_file = f"{tempfile.mkdtemp()}/{file_name}"
sanitized_file_name = sanitize_filename(file_name)

out_file = f"{tempfile.mkdtemp()}/{sanitized_file_name}"
with open(out_file, "w") as fp:
fp.write(json.dumps(value, default=str))

Expand Down
Loading

0 comments on commit 90b6093

Please sign in to comment.