[Kimchi-devel] [PATCH 1/3] bugfix: Fix regexp in "kimchi.utils.get_next_clone_name"

Royce Lv lvroyce at linux.vnet.ibm.com
Thu Dec 11 08:15:15 UTC 2014


Reviewed-by: Royce Lv<lvroyce at linux.vnet.ibm.com>
On 2014年12月10日 11:17, Crístian Viana wrote:
> The regular expression used in the function
> "kimchi.utils.get_next_clone_name" has an extra '-' which
> isn't needed.
>
> The following commands, executed from an interactive Python shell,
> demonstrate the bug:
>
>>>> from kimchi.utils import get_next_clone_name
>>>> get_next_clone_name(['foo'], 'index', '.html')
> u'index-clone-1.html'
>>>> get_next_clone_name(['foo', 'index-clone-1.html'], 'index', '.html')
> u'index-clone-1.html'
>
> Even though the name 'index-clone-1.html' is provided as an existing
> name, the function still returns a duplicate value.
>
> Fix the regular expression by removing an unnecessary character.
>
> The following commands demonstrate the bug fix:
>
>>>> from kimchi.utils import get_next_clone_name
>>>> get_next_clone_name(['foo'], 'index', '.html')
> u'index-clone-1.html'
>>>> get_next_clone_name(['foo', 'index-clone-1.html'], 'index', '.html')
> u'index-clone-2.html'
>>>> get_next_clone_name(['foo', 'index-clone-1.html', 'index-clone-2.html'], 'index', '.html')
> u'index-clone-3.html'
>
> Signed-off-by: Crístian Viana <vianac at linux.vnet.ibm.com>
> ---
>   src/kimchi/utils.py | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/kimchi/utils.py b/src/kimchi/utils.py
> index 989e370..3af701c 100644
> --- a/src/kimchi/utils.py
> +++ b/src/kimchi/utils.py
> @@ -335,7 +335,7 @@ def get_next_clone_name(all_names, basename, name_suffix=''):
>   
>       re_expr = u'%s-clone-(?P<%s>\d+)' % (basename, re_group_num)
>       if name_suffix != '':
> -        re_expr = u'%s-%s' % (re_expr, name_suffix)
> +        re_expr = u'%s%s' % (re_expr, name_suffix)
>   
>       max_num = 0
>       re_compiled = re.compile(re_expr)




More information about the Kimchi-devel mailing list