diff --git a/scripts/bash/create-new-feature.sh b/scripts/bash/create-new-feature.sh index 6c2f04b8bd..9c23807acd 100644 --- a/scripts/bash/create-new-feature.sh +++ b/scripts/bash/create-new-feature.sh @@ -201,10 +201,13 @@ unicode_words() { fi printf '%s' "$name" | "${python_cmd[@]}" -c ' import sys +import unicodedata value = sys.stdin.buffer.read().decode("utf-8") lower = str.maketrans("ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz") result = "".join( - char if char.isalpha() or char.isdecimal() else sys.argv[1] + char + if char.isalpha() or char.isdecimal() or unicodedata.category(char).startswith("M") + else sys.argv[1] for char in value.translate(lower) ) sys.stdout.buffer.write(result.encode("utf-8")) diff --git a/scripts/powershell/create-new-feature.ps1 b/scripts/powershell/create-new-feature.ps1 index edb75b3222..f4ac59ee36 100644 --- a/scripts/powershell/create-new-feature.ps1 +++ b/scripts/powershell/create-new-feature.ps1 @@ -93,11 +93,11 @@ function ConvertTo-UnicodeWords { param([string]$Name, [string]$Separator) $lowerName = ConvertTo-AsciiLower -Name $Name - return [regex]::Replace($lowerName, '[\uD800-\uDBFF][\uDC00-\uDFFF]|[^\p{L}\p{Nd}]', { + return [regex]::Replace($lowerName, '[\uD800-\uDBFF][\uDC00-\uDFFF]|[^\p{L}\p{M}\p{Nd}]', { param($match) if ($match.Length -eq 2) { $category = [System.Globalization.CharUnicodeInfo]::GetUnicodeCategory($match.Value, 0) - if ($category.ToString() -match '(Letter|DecimalDigitNumber)$') { + if ($category.ToString() -match '(Letter|Mark|DecimalDigitNumber)$') { return $match.Value } } diff --git a/scripts/python/create_new_feature.py b/scripts/python/create_new_feature.py index 2099a73708..3a15c6a845 100644 --- a/scripts/python/create_new_feature.py +++ b/scripts/python/create_new_feature.py @@ -9,6 +9,7 @@ import re import shlex import sys +import unicodedata from dataclasses import dataclass from pathlib import Path @@ -177,7 +178,11 @@ def _clean_branch_name(name: str) -> str: def _unicode_words(name: str, separator: str) -> str: return "".join( - char if char.isalpha() or char.isdecimal() else separator + char + if char.isalpha() + or char.isdecimal() + or unicodedata.category(char).startswith("M") + else separator for char in name.translate(_ASCII_LOWER) ) diff --git a/tests/test_create_new_feature_python_parity.py b/tests/test_create_new_feature_python_parity.py index e98f65e463..9ef5b9299b 100644 --- a/tests/test_create_new_feature_python_parity.py +++ b/tests/test_create_new_feature_python_parity.py @@ -17,6 +17,7 @@ from tests.conftest import requires_bash from tests.parity_helpers import ( HAS_POWERSHELL, + HAS_PWSH, WINDOWS_POWERSHELL, _bash_posix_path, bash_cmd, @@ -196,6 +197,50 @@ def test_unicode_number_categories_match( assert json_stdout(result)["BRANCH_NAME"] == expected +@pytest.mark.parametrize( + "variant", + [ + pytest.param("bash", marks=requires_bash), + "python", + pytest.param( + "pwsh", + marks=pytest.mark.skipif(not HAS_PWSH, reason="pwsh not available"), + ), + pytest.param( + "windows-powershell-5.1", + marks=pytest.mark.skipif( + not WINDOWS_POWERSHELL, reason="Windows PowerShell 5.1 not available" + ), + ), + ], +) +@pytest.mark.parametrize( + ("description", "expected"), + [ + ("नमस्ते दुनिया", "001-नमस्ते-दुनिया"), + ("สร้างระบบล็อกอิน", "001-สร้างระบบล็อกอิน"), + ("مَرْحَبًا بالعالم", "001-مَرْحَبًا-بالعالم"), + ("cafe\u0301 menu", "001-cafe\u0301-menu"), + ], + ids=["devanagari", "thai", "arabic_diacritics", "decomposed_accent"], +) +def test_combining_marks_stay_inside_words( + repo: Path, variant: str, description: str, expected: str +) -> None: + if variant in ("pwsh", "windows-powershell-5.1"): + exe = "pwsh" if variant == "pwsh" else WINDOWS_POWERSHELL + script = repo / ".specify/scripts/powershell/create-new-feature.ps1" + cmd = [exe, "-NoProfile", "-File", str(script), "-Json", "-DryRun", description] + else: + command = {"bash": bash_cmd, "python": py_cmd}[variant] + cmd = command(repo, SCRIPT, "--json", "--dry-run", description) + + result = run(cmd, repo) + + assert result.returncode == 0, result.stderr + assert json_stdout(result)["BRANCH_NAME"] == expected + + @requires_bash def test_bash_reports_missing_utf8_locale_for_unicode_only( repo: Path, tmp_path: Path