Patchwork [V3] config: honour the trusted flag in ui.configint

login
register
mail settings
Submitter Martijn Pieters
Date March 12, 2017, 6:43 p.m.
Message ID <35cda6af86792b3fa979.1489344216@mjpieters-mbp>
Download mbox | patch
Permalink /patch/19200/
State Accepted
Headers show

Comments

Martijn Pieters - March 12, 2017, 6:43 p.m.
# HG changeset patch
# User Martijn Pieters <mjpieters@fb.com>
# Date 1489344211 25200
#      Sun Mar 12 11:43:31 2017 -0700
# Node ID 35cda6af86792b3fa979c41709d3742f8443af31
# Parent  abf029200e198878a4576a87e095bd8d77d9cea9
config: honour the trusted flag in ui.configint
Yuya Nishihara - March 17, 2017, 1:14 p.m.
On Sun, 12 Mar 2017 11:43:36 -0700, Martijn Pieters wrote:
> # HG changeset patch
> # User Martijn Pieters <mjpieters@fb.com>
> # Date 1489344211 25200
> #      Sun Mar 12 11:43:31 2017 -0700
> # Node ID 35cda6af86792b3fa979c41709d3742f8443af31
> # Parent  abf029200e198878a4576a87e095bd8d77d9cea9
> config: honour the trusted flag in ui.configint

s/configint/configbytes/ and queued, thanks.

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -452,7 +452,7 @@ 
         ConfigError: foo.invalid is not a byte quantity ('somevalue')
         """
 
-        value = self.config(section, name)
+        value = self.config(section, name, None, untrusted)
         if value is None:
             if not isinstance(default, str):
                 return default
diff --git a/tests/test-trusted.py b/tests/test-trusted.py
--- a/tests/test-trusted.py
+++ b/tests/test-trusted.py
@@ -201,3 +201,41 @@ 
     testui(debug=True, silent=True)
 except error.ParseError as inst:
     print(inst)
+
+print()
+print('# access typed information')
+with open('.hg/hgrc', 'w') as f:
+    f.write('''\
+[foo]
+sub=main
+sub:one=one
+sub:two=two
+path=monty/python
+bool=true
+int=42
+bytes=81mb
+list=spam,ham,eggs
+''')
+u = testui(user='abc', group='def', cuser='foo', silent=True)
+print('# suboptions, trusted and untrusted')
+trusted = u.configsuboptions('foo', 'sub')
+untrusted = u.configsuboptions('foo', 'sub', untrusted=True)
+print(
+    (trusted[0], sorted(trusted[1].items())),
+    (untrusted[0], sorted(untrusted[1].items())))
+print('# path, trusted and untrusted')
+print(u.configpath('foo', 'path'), u.configpath('foo', 'path', untrusted=True))
+print('# bool, trusted and untrusted')
+print(u.configbool('foo', 'bool'), u.configbool('foo', 'bool', untrusted=True))
+print('# int, trusted and untrusted')
+print(
+    u.configint('foo', 'int', 0),
+    u.configint('foo', 'int', 0, untrusted=True))
+print('# bytes, trusted and untrusted')
+print(
+    u.configbytes('foo', 'bytes', 0),
+    u.configbytes('foo', 'bytes', 0, untrusted=True))
+print('# list, trusted and untrusted')
+print(
+    u.configlist('foo', 'list', []),
+    u.configlist('foo', 'list', [], untrusted=True))
diff --git a/tests/test-trusted.py.out b/tests/test-trusted.py.out
--- a/tests/test-trusted.py.out
+++ b/tests/test-trusted.py.out
@@ -177,3 +177,19 @@ 
 ('foo', '.hg/hgrc:1')
 # same user, same group
 ('foo', '.hg/hgrc:1')
+
+# access typed information
+# different user, different group
+not trusting file .hg/hgrc from untrusted user abc, group def
+# suboptions, trusted and untrusted
+(None, []) ('main', [('one', 'one'), ('two', 'two')])
+# path, trusted and untrusted
+None .hg/monty/python
+# bool, trusted and untrusted
+False True
+# int, trusted and untrusted
+0 42
+# bytes, trusted and untrusted
+0 84934656
+# list, trusted and untrusted
+[] ['spam', 'ham', 'eggs']