File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff 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 :
Original file line number Diff line number Diff 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
10721087class CollectorTest (unittest .TestCase ):
10731088
You can’t perform that action at this time.
0 commit comments