configtypes: Handle {1} correctly.
This commit is contained in:
parent
94b0f92b75
commit
4bdf00b148
@ -874,7 +874,7 @@ class FormatString(BaseType):
|
|||||||
s = self.transform(value)
|
s = self.transform(value)
|
||||||
try:
|
try:
|
||||||
return s.format(**{k: '' for k in self.fields})
|
return s.format(**{k: '' for k in self.fields})
|
||||||
except KeyError as e:
|
except (KeyError, IndexError) as e:
|
||||||
raise configexc.ValidationError(value, "Invalid placeholder "
|
raise configexc.ValidationError(value, "Invalid placeholder "
|
||||||
"{}".format(e))
|
"{}".format(e))
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
@ -1089,7 +1089,7 @@ class SearchEngineUrl(BaseType):
|
|||||||
raise configexc.ValidationError(value, "must contain \"{}\"")
|
raise configexc.ValidationError(value, "must contain \"{}\"")
|
||||||
try:
|
try:
|
||||||
value.format("")
|
value.format("")
|
||||||
except KeyError:
|
except (KeyError, IndexError) as e:
|
||||||
raise configexc.ValidationError(
|
raise configexc.ValidationError(
|
||||||
value, "may not contain {...} (use {{ and }} for literal {/})")
|
value, "may not contain {...} (use {{ and }} for literal {/})")
|
||||||
|
|
||||||
|
@ -1501,6 +1501,7 @@ class TestSearchEngineUrl:
|
|||||||
'foo', # no placeholder
|
'foo', # no placeholder
|
||||||
':{}', # invalid URL
|
':{}', # invalid URL
|
||||||
'foo{bar}baz{}', # {bar} format string variable
|
'foo{bar}baz{}', # {bar} format string variable
|
||||||
|
'{1}{}', # numbered format string variable
|
||||||
])
|
])
|
||||||
def test_validate_invalid(self, klass, val):
|
def test_validate_invalid(self, klass, val):
|
||||||
with pytest.raises(configexc.ValidationError):
|
with pytest.raises(configexc.ValidationError):
|
||||||
@ -1761,6 +1762,7 @@ class TestFormatString:
|
|||||||
@pytest.mark.parametrize('val', [
|
@pytest.mark.parametrize('val', [
|
||||||
'{foo} {bar} {baz}',
|
'{foo} {bar} {baz}',
|
||||||
'{foo} {bar',
|
'{foo} {bar',
|
||||||
|
'{1}',
|
||||||
'',
|
'',
|
||||||
])
|
])
|
||||||
def test_validate_invalid(self, typ, val):
|
def test_validate_invalid(self, typ, val):
|
||||||
|
Loading…
Reference in New Issue
Block a user