Skip to content

Commit 39b7e60

Browse files
committed
fix: check valid filename, file encoding
1 parent 0bc62b7 commit 39b7e60

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

util/find_problems.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def make_problem_content(template, problem: dict) -> str:
6666

6767

6868
def write_all_text(path: str, text: str) -> None:
69-
f = open(path, 'w')
69+
f = open(path, 'w',encoding='utf8')
7070
f.write(text)
7171
f.close()
7272

@@ -196,8 +196,10 @@ def execute(app: CommandLineParser) -> None:
196196

197197
for problem in problems_info:
198198
content = make_problem_content(__template, problem)
199+
dir_name = ''.join(x for x in problem['name'] if x.isalnum())
200+
199201
problem_dir = os.path.join(
200-
target_dir, f"[{problem['id']}]{problem['name']}")
202+
target_dir, f"[{problem['id']}]{dir_name}")
201203
if not os.path.isdir(problem_dir):
202204
os.mkdir(problem_dir)
203205

0 commit comments

Comments
 (0)