Merge "Improve removing quotes logic"

This commit is contained in:
Zuul 2019-08-14 20:49:52 +00:00 committed by Gerrit Code Review
commit c4d8fa7b88
2 changed files with 6 additions and 1 deletions

View File

@ -93,6 +93,11 @@ class StringTypeTests(TypeTestHelper, unittest.TestCase):
self.type_instance = types.String(quotes=True)
self.assertConvertedValue('foo bar"', 'foo bar"')
def test_single_quote_is_invalid(self):
self.type_instance = types.String(quotes=True)
self.assertInvalid('"')
self.assertInvalid("'")
def test_repr(self):
t = types.String()
self.assertEqual('String', repr(t))

View File

@ -144,7 +144,7 @@ class String(ConfigType):
value = str(value)
if self.quotes and value:
if value[0] in "\"'":
if value[-1] != value[0]:
if len(value) == 1 or value[-1] != value[0]:
raise ValueError('Non-closed quote: %s' % value)
value = value[1:-1]