forked from Ikalus1988/MisakaNet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlesson-slugify-windows-path-sanitation.json
More file actions
16 lines (16 loc) · 1.46 KB
/
Copy pathlesson-slugify-windows-path-sanitation.json
File metadata and controls
16 lines (16 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{
"task_id": "lesson-slugify-windows-path-sanitation",
"title": "Slugify filename sanitation crash on Windows and WSL",
"domain": "scripts",
"tags": [
"slugify",
"windows",
"wsl",
"sanitation",
"path-errors"
],
"problem": "When creating a new lesson using `scripts/new_lesson.py` (either interactively or via batch mode), if the user or agent supplies a title with special characters, slashes (`/`, `\\`), emojis, or Windows reserved names, the `slugify` logic crashes, generates invalid file paths, or attempts to write to reserved devices (like `CON` or `PRN` on Windows). This disrupts the creation workflow on Windows and WSL systems.",
"solution": "Hardened the `_slugify` logic in `scripts/new_lesson.py` using standard library libraries and safeguards:\n1. **Unicode Decompositions**: Used `unicodedata.normalize('NFKD', title)` to strip accents and normalize letters.\n2. **Slashes Normalization**: Replaced `/` and `\\` with `-` explicitly before regex stripping.\n3. **Hyphens Collapsing**: Collapsed multiple consecutive hyphens into a single hyphen and stripped leading/trailing hyphens.\n4. **Empty Fallback**: If the final slug is empty (e.g. purely emojis), generated a unique safe default name: `lesson-YYYYMMDD-HHMMSS`.\n5. **Reserved Words Prefixing**: Added a `safe-` prefix if the slug matches any Windows reserved name (e.g. `con` becomes `safe-con`).",
"source": "lessons/contrib/slugify-windows-path-sanitation.md",
"test_cmd": ""
}