Skip to content

Commit 4e4bb8d

Browse files
committed
Fix SonarQube path injection issue in init.py
1 parent 0bc1ede commit 4e4bb8d

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

scripts/init.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,9 @@ def toml_escape(s: str) -> str:
7373
escaped_author = toml_escape(author)
7474
escaped_email = toml_escape(email)
7575

76-
def update_file(filepath: str, file_replacements: list[tuple[str, str]]):
77-
path = Path(filepath)
76+
def update_file(path: Path, file_replacements: list[tuple[str, str]]):
7877
if not path.exists():
79-
secho(f" Warning: File {filepath} not found, skipping. ⚠️", fg="yellow")
78+
secho(f" Warning: File {path} not found, skipping. ⚠️", fg="yellow")
8079
return
8180

8281
content = path.read_text()
@@ -87,18 +86,18 @@ def update_file(filepath: str, file_replacements: list[tuple[str, str]]):
8786

8887
if new_content != content:
8988
path.write_text(new_content)
90-
secho(f" Updated {filepath} ✅", fg="blue")
89+
secho(f" Updated {path} ✅", fg="blue")
9190

92-
update_file("docs/reference/app.md", [(r"^::: project\.app", f"::: {source}.app")])
91+
update_file(Path("docs/reference/app.md"), [(r"^::: project\.app", f"::: {source}.app")])
9392
update_file(
94-
"mkdocs.yml",
93+
Path("mkdocs.yml"),
9594
[
9695
(r"^repo_name: .*", f"repo_name: {github}/{name}"),
9796
(r"^repo_url: .*", f"repo_url: https://github.com/{github}/{name}"),
9897
],
9998
)
10099
update_file(
101-
"pyproject.toml",
100+
Path("pyproject.toml"),
102101
[
103102
(r"^source = \[.*\]", f'source = ["{source}"]'),
104103
(r'^app = "project\.app:main"', f'app = "{source}.app:main"'),
@@ -107,9 +106,9 @@ def update_file(filepath: str, file_replacements: list[tuple[str, str]]):
107106
(r"^authors = \[.*\]", f'authors = ["{escaped_author} <{escaped_email}>"]'),
108107
],
109108
)
110-
update_file("docs/README.md", [(r"^# .*", f"# {description}")])
111-
update_file(".github/CODEOWNERS", [(r"@.*", f"@{github}")])
112-
update_file(".github/FUNDING.yml", [(r"^github: \[.*\]", f"github: [{github}]")])
109+
update_file(Path("docs/README.md"), [(r"^# .*", f"# {description}")])
110+
update_file(Path(".github/CODEOWNERS"), [(r"@.*", f"@{github}")])
111+
update_file(Path(".github/FUNDING.yml"), [(r"^github: \[.*\]", f"github: [{github}]")])
113112

114113

115114
@command(context_settings={"help_option_names": ["-h", "--help"]})

0 commit comments

Comments
 (0)