Skip to content

Commit 487fb76

Browse files
authored
Merge branch 'main' into bolt/performance-optimizations-15425688384079757854
Signed-off-by: Amr Abed <3361565+amrabed@users.noreply.github.com>
2 parents fdec01f + 392b7ec commit 487fb76

3 files changed

Lines changed: 123 additions & 108 deletions

File tree

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ rename = "scripts.rename:main"
1717
[dependency-groups]
1818
dev = [
1919
"pytest>=9.0.1",
20-
"ruff>=0.15.12",
21-
"coverage>=7.6.9",
20+
"ruff>=0.15.13",
21+
"coverage>=7.14.0",
2222
"pre-commit>=4.0.1",
2323
"pyright>=1.1.391",
2424
]
@@ -36,7 +36,7 @@ build-backend = "hatchling.build"
3636
line-length = 120
3737

3838
[tool.ruff.lint]
39-
select = ["E", "I"]
39+
select = ["E", "I", "S"]
4040

4141
[tool.coverage.run]
4242
branch = true

scripts/rename.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,27 @@
1414
@option("--email", required=True, help="Author email")
1515
@option("--github", required=True, help="GitHub username")
1616
def main(name: str, description: str, author: str, email: str, github: str):
17-
# Validate name to prevent directory traversal or other injection
17+
# Validate inputs to prevent configuration injection
18+
for label, value in [
19+
("name", name),
20+
("description", description),
21+
("author", author),
22+
("email", email),
23+
("github", github),
24+
]:
25+
if "\n" in value or "\r" in value:
26+
raise UsageError(f"Invalid {label}: newlines are not allowed.")
27+
if label != "description" and '"' in value:
28+
raise UsageError(f"Invalid {label}: double quotes are not allowed.")
29+
1830
if not re.match(r"^[a-zA-Z0-9_-]+$", name):
1931
raise UsageError(
2032
f"Invalid project name '{name}'. Only alphanumeric characters, dashes, and underscores are allowed."
2133
)
2234

35+
# Sanitize description for TOML double-quoted strings
36+
description = description.replace('"', '\\"')
37+
2338
source = name.replace("-", "_").lower()
2439

2540
echo(f"Initializing project '{name}' (source: '{source}')...")
@@ -59,7 +74,7 @@ def main(name: str, description: str, author: str, email: str, github: str):
5974
content = path.read_text()
6075
new_content = content
6176
for pattern, replacement in patterns:
62-
new_content = re.sub(pattern, replacement, new_content, flags=re.MULTILINE)
77+
new_content = re.sub(pattern, lambda _: replacement, content, flags=re.MULTILINE)
6378

6479
if new_content != content:
6580
path.write_text(new_content)

0 commit comments

Comments
 (0)