Commit 7f417b2a authored by Romain Courteaud's avatar Romain Courteaud Committed by Łukasz Nowak

Fix $$ escaping.

Squashed commit of the following:

commit ef1a217b
Author: Romain Courteaud <romain@nexedi.com>
Date:   Tue Oct 11 10:01:10 2011 +0200

    Escape $$ character to $.

    Do not escape when fetching dependency values.

commit 8232c9aa
Author: Antoine Catton <acatton@tiolive.com>
Date:   Mon Oct 10 09:57:12 2011 +0200

    Add tests for dollar sign escaping
parent ca7d109e
...@@ -1295,6 +1295,7 @@ class Options(UserDict.DictMixin): ...@@ -1295,6 +1295,7 @@ class Options(UserDict.DictMixin):
self._raw = data self._raw = data
self._cooked = {} self._cooked = {}
self._data = {} self._data = {}
self._non_escaped_data = {}
def _initialize(self): def _initialize(self):
name = self.name name = self.name
...@@ -1356,11 +1357,17 @@ class Options(UserDict.DictMixin): ...@@ -1356,11 +1357,17 @@ class Options(UserDict.DictMixin):
v = '$$'.join([self._sub(s, seen) for s in v.split('$$')]) v = '$$'.join([self._sub(s, seen) for s in v.split('$$')])
self._cooked[option] = v self._cooked[option] = v
def get(self, option, default=None, seen=None): def get(self, option, default=None, seen=None, escaped=True):
try: if escaped:
return self._data[option] try:
except KeyError: return self._data[option]
pass except KeyError:
pass
else:
try:
return self._non_escaped_data[option]
except KeyError:
pass
v = self._cooked.get(option) v = self._cooked.get(option)
if v is None: if v is None:
...@@ -1383,8 +1390,13 @@ class Options(UserDict.DictMixin): ...@@ -1383,8 +1390,13 @@ class Options(UserDict.DictMixin):
v = '$$'.join([self._sub(s, seen) for s in v.split('$$')]) v = '$$'.join([self._sub(s, seen) for s in v.split('$$')])
seen.pop() seen.pop()
self._non_escaped_data[option] = v
v = v.replace('$${', '${')
self._data[option] = v self._data[option] = v
return v if escaped:
return self._data[option]
else:
return self._non_escaped_data[option]
_template_split = re.compile('([$]{[^}]*})').split _template_split = re.compile('([$]{[^}]*})').split
_simple = re.compile('[-a-zA-Z0-9 ._]+$').match _simple = re.compile('[-a-zA-Z0-9 ._]+$').match
...@@ -1417,7 +1429,8 @@ class Options(UserDict.DictMixin): ...@@ -1417,7 +1429,8 @@ class Options(UserDict.DictMixin):
section, option = s section, option = s
if not section: if not section:
section = self.name section = self.name
v = self.buildout[section].get(option, None, seen) v = self.buildout[section].get(option, None, seen,
escaped=False)
if v is None: if v is None:
if option == '_buildout_section_name_': if option == '_buildout_section_name_':
v = self.name v = self.name
......
...@@ -3587,6 +3587,73 @@ def increment_on_command_line(): ...@@ -3587,6 +3587,73 @@ def increment_on_command_line():
recipe='zc.buildout:debug' recipe='zc.buildout:debug'
""" """
def bug_664539_simple_buildout():
r"""
>>> write('buildout.cfg', '''
... [buildout]
... parts = escape
...
... [escape]
... recipe = zc.buildout:debug
... foo = $${nonexistent:option}
... ''')
>>> print system(buildout),
Installing escape.
foo='${nonexistent:option}'
recipe='zc.buildout:debug'
"""
def bug_664539_reference():
r"""
>>> write('buildout.cfg', '''
... [buildout]
... parts = escape
...
... [escape]
... recipe = zc.buildout:debug
... foo = ${:bar}
... bar = $${nonexistent:option}
... ''')
>>> print system(buildout),
Installing escape.
bar='${nonexistent:option}'
foo='${nonexistent:option}'
recipe='zc.buildout:debug'
"""
def bug_664539_complex_buildout():
r"""
>>> write('buildout.cfg', '''
... [buildout]
... parts = escape
...
... [escape]
... recipe = zc.buildout:debug
... foo = ${level1:foo}
...
... [level1]
... recipe = zc.buildout:debug
... foo = ${level2:foo}
...
... [level2]
... recipe = zc.buildout:debug
... foo = $${nonexistent:option}
... ''')
>>> print system(buildout),
Installing level2.
foo='${nonexistent:option}'
recipe='zc.buildout:debug'
Installing level1.
foo='${nonexistent:option}'
recipe='zc.buildout:debug'
Installing escape.
foo='${nonexistent:option}'
recipe='zc.buildout:debug'
"""
###################################################################### ######################################################################
def make_py_with_system_install(make_py, sample_eggs): def make_py_with_system_install(make_py, sample_eggs):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment