Merge pull request #34220 from LeadSift/develop

Fixes #34181 no more newlines in long yaml encodes
This commit is contained in:
Mike Place 2016-06-23 10:51:48 -07:00 committed by GitHub
commit f65535a307
2 changed files with 10 additions and 2 deletions

View File

@ -16,7 +16,7 @@ def yaml_dquote(text):
quote characters.
'''
with io.StringIO() as ostream:
yemitter = yaml.emitter.Emitter(ostream)
yemitter = yaml.emitter.Emitter(ostream, width=six.MAXSIZE)
yemitter.write_double_quoted(six.text_type(text))
return ostream.getvalue()
@ -28,7 +28,7 @@ def yaml_squote(text):
quote characters.
'''
with io.StringIO() as ostream:
yemitter = yaml.emitter.Emitter(ostream)
yemitter = yaml.emitter.Emitter(ostream, width=six.MAXSIZE)
yemitter.write_single_quoted(six.text_type(text))
return ostream.getvalue()

View File

@ -547,10 +547,18 @@ class UtilsTestCase(TestCase):
for teststr in (r'"\ []{}"',):
self.assertEqual(teststr, yaml.safe_load(utils.yamlencoding.yaml_dquote(teststr)))
def test_yaml_dquote_doesNotAddNewLines(self):
teststr = '"' * 100
self.assertNotIn('\n', utils.yamlencoding.yaml_dquote(teststr))
def test_yaml_squote(self):
ret = utils.yamlencoding.yaml_squote(r'"')
self.assertEqual(ret, r"""'"'""")
def test_yaml_squote_doesNotAddNewLines(self):
teststr = "'" * 100
self.assertNotIn('\n', utils.yamlencoding.yaml_squote(teststr))
def test_yaml_encode(self):
for testobj in (None, True, False, '[7, 5]', '"monkey"', 5, 7.5, "2014-06-02 15:30:29.7"):
self.assertEqual(testobj, yaml.safe_load(utils.yamlencoding.yaml_encode(testobj)))