Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
317ab06b
Commit
317ab06b
authored
Sep 04, 2014
by
James Cammarata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing multiline parsing to preserve newlines
Fixes #8813
parent
bac97c83
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
25 deletions
+25
-25
lib/ansible/module_utils/splitter.py
+22
-22
test/integration/roles/test_command_shell/tasks/main.yml
+2
-2
test/units/TestUtils.py
+1
-1
No files found.
lib/ansible/module_utils/splitter.py
View file @
317ab06b
...
...
@@ -76,7 +76,7 @@ def split_args(args):
do_decode
=
True
except
UnicodeDecodeError
:
do_decode
=
False
items
=
args
.
s
plit
(
'
'
)
items
=
args
.
s
trip
()
.
split
(
'
\n
'
)
# iterate over the tokens, and reassemble any that may have been
# split on a space inside a jinja2 block.
...
...
@@ -94,22 +94,16 @@ def split_args(args):
# now we loop over each split chunk, coalescing tokens if the white space
# split occurred within quotes or a jinja2 block of some kind
for
item
in
items
:
for
item
idx
,
item
in
enumerate
(
items
)
:
# we split on spaces and newlines separately, so that we
# can tell which character we split on for reassembly
# inside quotation characters
tokens
=
item
.
s
plit
(
'
\n
'
)
tokens
=
item
.
s
trip
()
.
split
(
'
'
)
line_continuation
=
False
for
idx
,
token
in
enumerate
(
tokens
):
# if there was a newline split, we will re-assemble using
# newlines, otherwise we re-assemble using spaces
spacer
=
' '
if
idx
>
0
:
spacer
=
'
\n
'
# if we hit a line continuation character, but
# we're not inside quotes, ignore it and continue
# on to the next token while setting a flag
...
...
@@ -136,7 +130,15 @@ def split_args(args):
params
.
append
(
token
)
appended
=
True
elif
print_depth
or
block_depth
or
comment_depth
or
inside_quotes
or
was_inside_quotes
:
params
[
-
1
]
=
"
%
s
%
s
%
s"
%
(
params
[
-
1
],
spacer
,
token
)
if
idx
==
0
and
not
inside_quotes
and
was_inside_quotes
:
params
[
-
1
]
=
"
%
s
%
s"
%
(
params
[
-
1
],
token
)
elif
len
(
tokens
)
>
1
:
spacer
=
''
if
idx
>
0
:
spacer
=
' '
params
[
-
1
]
=
"
%
s
%
s
%
s"
%
(
params
[
-
1
],
spacer
,
token
)
else
:
params
[
-
1
]
=
"
%
s
\n
%
s"
%
(
params
[
-
1
],
token
)
appended
=
True
# if the number of paired block tags is not the same, the depth has changed, so we calculate that here
...
...
@@ -162,19 +164,17 @@ def split_args(args):
# finally, if we're at zero depth for all blocks and not inside quotes, and have not
# yet appended anything to the list of params, we do so now
if
not
(
print_depth
or
block_depth
or
comment_depth
)
and
not
inside_quotes
and
not
appended
and
token
!=
''
:
# if the spacer was a newline, prepend this param
# with it so that newlines are preserved, unless
# we previously hit a line continuation character
if
spacer
==
'
\n
'
:
if
line_continuation
:
params
.
append
(
token
)
else
:
params
.
append
(
'
\n
%
s'
%
token
)
else
:
params
.
append
(
token
)
params
.
append
(
token
)
# if this was the last token in the list, and we have more than
# one item (meaning we split on newlines), add a newline back here
# to preserve the original structure
if
len
(
items
)
>
1
and
itemidx
!=
len
(
items
)
-
1
and
not
line_continuation
:
if
not
params
[
-
1
]
.
endswith
(
'
\n
'
):
params
[
-
1
]
+=
'
\n
'
# always clear the line continuation flag
line_continuation
=
False
# always clear the line continuation flag
line_continuation
=
False
# If we're done and things are not at zero depth or we're still inside quotes,
# raise an error to indicate that the args were unbalanced
...
...
test/integration/roles/test_command_shell/tasks/main.yml
View file @
317ab06b
...
...
@@ -181,8 +181,8 @@
args
:
executable
:
/bin/bash
shell
:
|
echo this is a
"multiline echo"
echo this is a
\
"multiline echo"
\
"with a new line
in quotes" \
| md5sum \
...
...
test/units/TestUtils.py
View file @
317ab06b
...
...
@@ -715,7 +715,7 @@ class TestUtils(unittest.TestCase):
# in memory of neighbors cat
# we preserve line breaks unless a line continuation character preceeds them
'a {
%
if x
%
} y {
%
else
%
} {{meow}} {
%
endif
%
} "cookie
\n
chip"
\\\n
done
\n
and done'
,
[
'a'
,
'{
%
if x
%
}'
,
'y'
,
'{
%
else
%
}'
,
'{{meow}}'
,
'{
%
endif
%
}'
,
'"cookie
\n
chip"'
,
'done
'
,
'
\n
and'
,
'done'
]
[
'a'
,
'{
%
if x
%
}'
,
'y'
,
'{
%
else
%
}'
,
'{{meow}}'
,
'{
%
endif
%
}'
,
'"cookie
\n
chip"'
,
'done
\n
'
,
'
and'
,
'done'
]
)
# test space preservation within quotes
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment