Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit f511729

Browse files
committed
handle tabs and spaces in passed JSON values - longstanding issue not noted till today
1 parent d4ac4a4 commit f511729

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

cli4/cli4.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ def dump_commands_from_web(cf):
3434
else:
3535
sys.stdout.write('%-6s %s\n' % (r['action'], r['cmd']))
3636

37+
def strip_multiline(s):
38+
""" remove leading/trailing tabs/spaces on each line"""
39+
# This hack is needed in order to use yaml.safe_load() on JSON text - tabs are not allowed
40+
return '\n'.join([l.strip() for l in s.splitlines()])
41+
3742
def run_command(cf, method, command, params=None, content=None, files=None):
3843
"""run the command line"""
3944
# remove leading and trailing /'s
@@ -403,6 +408,9 @@ def do_it(args):
403408
#value = json.loads(value) - changed to yaml code to remove unicode string issues
404409
if yaml is None:
405410
sys.exit('cli4: install yaml support')
411+
# cleanup string before parsing so that yaml.safe.load does not complain about whitespace
412+
# >>> found character '\t' that cannot start any token <<<
413+
value_string = strip_multiline(value_string)
406414
try:
407415
value = yaml.safe_load(value_string)
408416
except yaml.parser.ParserError as e:

0 commit comments

Comments
 (0)