Skip to content

Commit b8e6607

Browse files
Apply changes from Review (- WIP #291 -)
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 6a504c6 commit b8e6607

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

docs/utils.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,25 @@ def _validate_git_ref(ref: str) -> str:
6565
...
6666
ValueError: Invalid Git reference: invalid..ref
6767
"""
68-
if not re.match(r'^[a-zA-Z0-9][a-zA-Z0-9_\-./]*$', ref) or '..' in ref:
68+
# Git reference validation pattern
69+
# Enforces:
70+
# - Must start with alphanumeric character
71+
# - Can contain alphanumeric characters, underscore, hyphen, forward slash, and dot
72+
GIT_REF_PATTERN = r'^[a-zA-Z0-9][a-zA-Z0-9_\-./]*$'
73+
74+
def _validate_git_ref(ref: str) -> str:
75+
"""
76+
Validate if the provided string is a valid Git reference.
77+
78+
Git reference naming rules:
79+
- Must start with an alphanumeric character
80+
- Can contain alphanumeric characters, underscore, hyphen, forward slash, and dot
81+
- Cannot contain consecutive dots (..)
82+
...
83+
"""
84+
if not re.match(GIT_REF_PATTERN, ref) or '..' in ref:
85+
raise ValueError(f"Invalid Git reference: {ref}")
86+
return ref
6987
raise ValueError(f"Invalid Git reference: {ref}")
7088
return ref
7189

0 commit comments

Comments
 (0)