Patchwork [V2] commitextras: make sure keys contains ascii letters, numbers, '_' and '-' only

login
register
mail settings
Submitter Pulkit Goyal
Date July 29, 2017, 6:33 p.m.
Message ID <f0fb7e786aceea12cb42.1501353229@workspace>
Download mbox | patch
Permalink /patch/22578/
State Accepted
Headers show

Comments

Pulkit Goyal - July 29, 2017, 6:33 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1501207975 -19800
#      Fri Jul 28 07:42:55 2017 +0530
# Branch stable
# Node ID f0fb7e786aceea12cb422b100c5ccf047b61d45d
# Parent  850d2ec2cf6a266987a401752c909f95dd8c4c53
commitextras: make sure keys contains ascii letters, numbers, '_' and '-' only
Yuya Nishihara - July 30, 2017, 4:39 a.m.
On Sun, 30 Jul 2017 00:03:49 +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1501207975 -19800
> #      Fri Jul 28 07:42:55 2017 +0530
> # Branch stable
> # Node ID f0fb7e786aceea12cb422b100c5ccf047b61d45d
> # Parent  850d2ec2cf6a266987a401752c909f95dd8c4c53
> commitextras: make sure keys contains ascii letters, numbers, '_' and '-' only

Queued, thanks.

Can you add a check for an empty key as a follow up?
Pulkit Goyal - July 30, 2017, 6:50 a.m.
On Sun, Jul 30, 2017 at 10:09 AM, Yuya Nishihara <yuya@tcha.org> wrote:
> On Sun, 30 Jul 2017 00:03:49 +0530, Pulkit Goyal wrote:
>> # HG changeset patch
>> # User Pulkit Goyal <7895pulkit@gmail.com>
>> # Date 1501207975 -19800
>> #      Fri Jul 28 07:42:55 2017 +0530
>> # Branch stable
>> # Node ID f0fb7e786aceea12cb422b100c5ccf047b61d45d
>> # Parent  850d2ec2cf6a266987a401752c909f95dd8c4c53
>> commitextras: make sure keys contains ascii letters, numbers, '_' and '-' only
>
> Queued, thanks.
>
> Can you add a check for an empty key as a follow up?

Oh, thanks for catching that. Sure I will.

Patch

diff --git a/hgext/commitextras.py b/hgext/commitextras.py
--- a/hgext/commitextras.py
+++ b/hgext/commitextras.py
@@ -9,6 +9,8 @@ 
 
 from __future__ import absolute_import
 
+import re
+
 from mercurial.i18n import _
 from mercurial import (
     commands,
@@ -52,6 +54,10 @@ 
                                 "KEY=VALUE format")
                         raise error.Abort(msg % raw)
                     k, v = raw.split('=', 1)
+                    if re.search('[^\w-]', k):
+                        msg = _("keys can only contain ascii letters, digits,"
+                                " '_' and '-'")
+                        raise error.Abort(msg)
                     if k in usedinternally:
                         msg = _("key '%s' is used internally, can't be set "
                                 "manually")
diff --git a/tests/test-commit.t b/tests/test-commit.t
--- a/tests/test-commit.t
+++ b/tests/test-commit.t
@@ -135,6 +135,9 @@ 
   $ hg commit -m "adding internal used extras" --extra amend_source=hash
   abort: key 'amend_source' is used internally, can't be set manually
   [255]
+  $ hg commit -m "special chars in extra" --extra id@phab=214
+  abort: keys can only contain ascii letters, digits, '_' and '-'
+  [255]
   $ hg commit -m "adding extras" --extra sourcehash=foo --extra oldhash=bar
   $ hg log -r . -T '{extras % "{extra}\n"}'
   branch=default