Patchwork commitextras: make sure keys are not empty

login
register
mail settings
Submitter Pulkit Goyal
Date July 30, 2017, 7:31 a.m.
Message ID <806351695c6a27a1a356.1501399879@workspace>
Download mbox | patch
Permalink /patch/22585/
State Accepted
Headers show

Comments

Pulkit Goyal - July 30, 2017, 7:31 a.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1501397386 -19800
#      Sun Jul 30 12:19:46 2017 +0530
# Branch stable
# Node ID 806351695c6a27a1a35600c637299aad3d9b6b52
# Parent  92f7dcf9a40b056573be89f611e1f093521696d7
commitextras: make sure keys are not empty

Thanks to Yuya for catching this.
Yuya Nishihara - July 30, 2017, 12:58 p.m.
On Sun, 30 Jul 2017 13:01:19 +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1501397386 -19800
> #      Sun Jul 30 12:19:46 2017 +0530
> # Branch stable
> # Node ID 806351695c6a27a1a35600c637299aad3d9b6b52
> # Parent  92f7dcf9a40b056573be89f611e1f093521696d7
> commitextras: make sure keys are not empty

Queued, thanks.

Patch

diff --git a/hgext/commitextras.py b/hgext/commitextras.py
--- a/hgext/commitextras.py
+++ b/hgext/commitextras.py
@@ -54,6 +54,9 @@ 
                                 "KEY=VALUE format")
                         raise error.Abort(msg % raw)
                     k, v = raw.split('=', 1)
+                    if not k:
+                        msg = _("unable to parse '%s', keys can't be empty")
+                        raise error.Abort(msg % raw)
                     if re.search('[^\w-]', k):
                         msg = _("keys can only contain ascii letters, digits,"
                                 " '_' and '-'")
diff --git a/tests/test-commit.t b/tests/test-commit.t
--- a/tests/test-commit.t
+++ b/tests/test-commit.t
@@ -138,6 +138,9 @@ 
   $ hg commit -m "special chars in extra" --extra id@phab=214
   abort: keys can only contain ascii letters, digits, '_' and '-'
   [255]
+  $ hg commit -m "empty key" --extra =value
+  abort: unable to parse '=value', keys can't be empty
+  [255]
   $ hg commit -m "adding extras" --extra sourcehash=foo --extra oldhash=bar
   $ hg log -r . -T '{extras % "{extra}\n"}'
   branch=default