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