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

Augie Fackler raf at durin42.com
Sun Mar 12 14:36:19 EDT 2017


On Sun, Mar 12, 2017 at 10:34:33AM -0700, Martijn Pieters wrote:
> # HG changeset patch
> # User Martijn Pieters <mjpieters at fb.com>
> # Date 1489340031 25200
> #      Sun Mar 12 10:33:51 2017 -0700
> # Node ID 55a2a84cb75e7bbfb9dcd510b686de417fb9dfab
> # Parent  abf029200e198878a4576a87e095bd8d77d9cea9
> config: honour the trusted flag in ui.configint

Queued, thanks.

>
> 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,38 @@
>      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')
> +print(u.configsuboptions('foo', 'sub'), u.configsuboptions('foo', 'sub', untrusted=True))
> +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', {'two': 'two', 'one': 'one'})
> +# 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']


More information about the Mercurial-devel mailing list