Patchwork [default] ui: fix ui.configdate for invalid dates

login
register
mail settings
Submitter Boris Feld
Date May 24, 2017, 3:07 p.m.
Message ID <6d7a1390eb6694847cd8.1495638420@FB>
Download mbox | patch
Permalink /patch/20878/
State Accepted
Headers show

Comments

Boris Feld - May 24, 2017, 3:07 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1495547090 -7200
#      Tue May 23 15:44:50 2017 +0200
# Node ID 6d7a1390eb6694847cd8c4b90ad38434b362cad4
# Parent  75544176bc28ad24405c77d592971d525aeca8b8
# EXP-Topic fixuiconfigdate
ui: fix ui.configdate for invalid dates

a7dce526c462 introduced util._parsedate with the aim to be used in
ui.configdate but ui.configdate was using util.parsedate instead. It have the
impact of raising an AbortError in case of an invalid date instead of a
ConfigError exception. Fix ui.configdate to use the right function and add a
test for invalid dates.

Thanks to Yuya for the catch!
Augie Fackler - May 24, 2017, 8:30 p.m.
On Wed, May 24, 2017 at 05:07:00PM +0200, Boris Feld wrote:
> # HG changeset patch
> # User Boris Feld <boris.feld@octobus.net>
> # Date 1495547090 -7200
> #      Tue May 23 15:44:50 2017 +0200
> # Node ID 6d7a1390eb6694847cd8c4b90ad38434b362cad4
> # Parent  75544176bc28ad24405c77d592971d525aeca8b8
> # EXP-Topic fixuiconfigdate
> ui: fix ui.configdate for invalid dates

queued, thanks

Patch

diff -r 75544176bc28 -r 6d7a1390eb66 mercurial/ui.py
--- a/mercurial/ui.py	Mon May 22 13:35:22 2017 -0400
+++ b/mercurial/ui.py	Tue May 23 15:44:50 2017 +0200
@@ -607,7 +607,7 @@ 
         (0, 0)
         """
         if self.config(section, name, default, untrusted):
-            return self.configwith(util.parsedate, section, name, default,
+            return self.configwith(util.rawparsedate, section, name, default,
                                    'date', untrusted)
         return default
 
diff -r 75544176bc28 -r 6d7a1390eb66 tests/test-ui-config.py
--- a/tests/test-ui-config.py	Mon May 22 13:35:22 2017 -0400
+++ b/tests/test-ui-config.py	Tue May 23 15:44:50 2017 +0200
@@ -32,6 +32,9 @@ 
     'lists.list16="longer quotation" with "no ending quotation',
     'lists.list17=this is \\" "not a quotation mark"',
     'lists.list18=\n \n\nding\ndong',
+    'date.epoch=0 0',
+    'date.birth=2005-04-19T00:00:00',
+    'date.invalid=0'
     ])
 
 print(repr(testui.configitems('values')))
@@ -82,6 +85,9 @@ 
 print(repr(testui.configlist('lists', 'unknown', 'foo, bar')))
 print(repr(testui.configlist('lists', 'unknown', ['foo bar'])))
 print(repr(testui.configlist('lists', 'unknown', ['foo', 'bar'])))
+print("---")
+print(repr(testui.configdate('date', 'epoch')))
+print(repr(testui.configdate('date', 'birth')))
 
 print(repr(testui.config('values', 'String')))
 
@@ -101,3 +107,7 @@ 
     testui.configint('values', 'intinvalid')
 except error.ConfigError:
     print('intinvalid')
+try:
+    testui.configdate('date', 'invalid')
+except error.ConfigError:
+    print('dateinvalid')
\ No newline at end of file
diff -r 75544176bc28 -r 6d7a1390eb66 tests/test-ui-config.py.out
--- a/tests/test-ui-config.py.out	Mon May 22 13:35:22 2017 -0400
+++ b/tests/test-ui-config.py.out	Tue May 23 15:44:50 2017 +0200
@@ -43,7 +43,11 @@ 
 ['foo', 'bar']
 ['foo bar']
 ['foo', 'bar']
+---
+(0, 0)
+(1113868800, 0)
 None
 True
 boolinvalid
 intinvalid
+dateinvalid