Skip to content

Commit 881dc5c

Browse files
committed
Merge branch '323_colon_in_text_field' into develop
2 parents b14bb7d + 7acf976 commit 881dc5c

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/attributecode/model.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,16 @@ def serialize(self):
175175
# insert 4 spaces for newline values
176176
value = u' '.join(value)
177177
else:
178-
value = u''.join(value)
178+
# See https://github.com/nexB/aboutcode-toolkit/issues/323
179+
# The yaml.load() will throw error if the parsed value
180+
# contains ': ' character. A work around is to put a pipe, '|'
181+
# to indicate the whole value as a string
182+
if value and ': ' in value[0]:
183+
value.insert(0, u'|\n')
184+
# insert 4 spaces for newline values
185+
value = u' '.join(value)
186+
else:
187+
value = u''.join(value)
179188

180189
serialized = u'%(name)s:' % locals()
181190
if value:

tests/test_model.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,21 @@ def test_write_output_json(self):
10681068
expected = get_test_loc('load/expected.json')
10691069
check_json(expected, result)
10701070

1071+
def test_colon_in_value(self):
1072+
test = u'''about_resource: .
1073+
name: AboutCode
1074+
version: v: 0.11.0
1075+
'''
1076+
expected = u'''about_resource: .
1077+
name: AboutCode
1078+
version: |
1079+
v: 0.11.0
1080+
'''
1081+
a = model.About()
1082+
base_dir = 'some_dir'
1083+
a.loads(test, base_dir)
1084+
dumped = a.dumps(with_absent=False, with_empty=False)
1085+
assert dumped == expected
10711086

10721087
class CollectorTest(unittest.TestCase):
10731088

0 commit comments

Comments
 (0)