File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change 1+ import unittest
2+
3+ from wdlgen import ParameterMeta
4+
5+
6+ class TestParamMeta (unittest .TestCase ):
7+ def test_quote_sanitise (self ):
8+ meta = ParameterMeta (foo = '"bar"' ).get_string ()
9+ self .assertEqual ('foo: "\\ "bar\\ ""' , meta )
10+
11+ def test_nl_sanitise (self ):
12+ meta = ParameterMeta (foo = "bar\n baz" ).get_string ()
13+ self .assertEqual ('foo: "bar\\ nbaz"' , meta )
14+
15+ def test_backslackquote_sanitise (self ):
16+ meta = ParameterMeta (foo = 'bar\\ "' ).get_string ()
17+ self .assertEqual ('foo: "bar\\ \\ \\ ""' , meta )
Original file line number Diff line number Diff line change @@ -14,7 +14,12 @@ def convert_python_value_to_wdl_literal(val) -> str:
1414 if isinstance (val , bool ):
1515 return "true" if val else "false"
1616 if isinstance (val , str ):
17- return f'"{ val } "'
17+ # sanitise string here
18+ sanitised = val \
19+ .replace ("\\ " , "\\ \\ " )\
20+ .replace ("\n " , "\\ n" )\
21+ .replace ('"' , '\\ "' )
22+ return f'"{ sanitised } "'
1823
1924 return str (val )
2025
You can’t perform that action at this time.
0 commit comments