Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion scripts/bash/create-new-feature.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
4 changes: 2 additions & 2 deletions scripts/powershell/create-new-feature.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
7 changes: 6 additions & 1 deletion scripts/python/create_new_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import re
import shlex
import sys
import unicodedata
from dataclasses import dataclass
from pathlib import Path

Expand Down Expand Up @@ -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)
)

Expand Down
45 changes: 45 additions & 0 deletions tests/test_create_new_feature_python_parity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down