Skip to content

Commit 5716f33

Browse files
kimwoo123zzzeek
authored andcommitted
Add colon (:) to invalid char for revision name add unittest
Disallow ':' character in custom revision identifiers. Previously, using a colon in a revision ID (e.g., 'REV:1') would create the revision, however revisions with colons in them are not correctly interpreted by other commands, as it overlaps with the revision range syntax. Pull request courtesy Kim Wooseok with original implementation by Hrushikesh Patil. Fixes: #1540 Closes: #1741 Pull-request: #1741 Pull-request-sha: 3894b1f Change-Id: Ie935f0e04981a0b3d0ac8a2ac03ffebce898280a
1 parent 709c0be commit 5716f33

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

alembic/script/revision.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
_TR = TypeVar("_TR", bound=Optional[_RevisionOrStr])
4646

4747
_relative_destination = re.compile(r"(?:(.+?)@)?(\w+)?((?:\+|-)\d+)")
48-
_revision_illegal_chars = ["@", "-", "+"]
48+
_revision_illegal_chars = ["@", "-", "+", ":"]
4949

5050

5151
class _CollectRevisionsProtocol(Protocol):

docs/build/unreleased/1540.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.. change::
2+
:tags: bug, commands
3+
:tickets: 1540
4+
5+
Disallow ':' character in custom revision identifiers. Previously, using a
6+
colon in a revision ID (e.g., 'REV:1') would create the revision, however
7+
revisions with colons in them are not correctly interpreted by other
8+
commands, as it overlaps with the revision range syntax. Pull request
9+
courtesy Kim Wooseok with original implementation by Hrushikesh Patil.

tests/test_script_production.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,16 @@ def test_illegal_revision_chars(self):
393393
rev_id="no@atsigns",
394394
)
395395

396+
assert_raises_message(
397+
util.CommandError,
398+
r"Character\(s\) ':' not allowed in "
399+
"revision identifier 'no:colons'",
400+
command.revision,
401+
self.cfg,
402+
message="some message",
403+
rev_id="no:colons",
404+
)
405+
396406
assert_raises_message(
397407
util.CommandError,
398408
r"Character\(s\) '-, @' not allowed in revision "

0 commit comments

Comments
 (0)