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
085ba4ff
Commit
085ba4ff
authored
Sep 11, 2014
by
James Cammarata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix quoting issues in lineinfile for individual single-quotes
Fixes #8806
parent
8d0c1dd2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
2 deletions
+69
-2
library/files/lineinfile
+7
-2
test/integration/roles/test_lineinfile/tasks/main.yml
+62
-0
No files found.
library/files/lineinfile
View file @
085ba4ff
...
...
@@ -369,14 +369,19 @@ def main():
# so we need to know if we should specifically unquote it.
should_unquote
=
not
is_quoted
(
line
)
# always add one layer of quotes
line
=
"'
%
s'"
%
line
# Replace escape sequences like '\n' while being sure
# not to replace octal escape sequences (\ooo) since they
# match the backref syntax.
if
backrefs
:
line
=
re
.
sub
(
r'(\\[0-9]{1,3})'
,
r'\\\1'
,
line
)
line
=
module
.
safe_eval
(
pipes
.
quote
(
line
)
)
line
=
module
.
safe_eval
(
line
)
# Now remove quotes around the string, if needed
# Now remove quotes around the string, if needed after
# removing the layer we added above
line
=
unquote
(
line
)
if
should_unquote
:
line
=
unquote
(
line
)
...
...
test/integration/roles/test_lineinfile/tasks/main.yml
View file @
085ba4ff
...
...
@@ -294,3 +294,65 @@
that
:
-
"
result.stat.md5
==
'65f955c2a9722fd43d07103d7756ff9b'"
###################################################################
# issue 8535
-
name
:
create a new file for testing quoting issues
file
:
dest={{output_dir}}/test_quoting.txt state=touch
register
:
result
-
name
:
assert the new file was created
assert
:
that
:
-
result.changed
-
name
:
use with_items to add code-like strings to the quoting txt file
lineinfile
:
>
dest={{output_dir}}/test_quoting.txt
line="{{ item }}"
insertbefore=BOF
with_items
:
-
"
'foo'"
-
"
dotenv.load();"
-
"
var
dotenv
=
require('dotenv');"
register
:
result
-
name
:
assert the quote test file was modified correctly
assert
:
that
:
-
result.results|length == 3
-
result.results[0].changed
-
result.results[0].item == "'foo'"
-
result.results[1].changed
-
result.results[1].item == "dotenv.load();"
-
result.results[2].changed
-
result.results[2].item == "var dotenv = require('dotenv');"
-
name
:
stat the quote test file
stat
:
path={{output_dir}}/test_quoting.txt
register
:
result
-
name
:
assert test md5 matches after backref line was replaced
assert
:
that
:
-
"
result.stat.md5
==
'29f349baf1b9c6703beeb346fe8dc669'"
-
name
:
insert a line into the quoted file with a single quote
lineinfile
:
dest={{output_dir}}/test_quoting.txt line="import g'"
register
:
result
-
name
:
assert that the quoted file was changed
assert
:
that
:
-
result.changed
-
name
:
stat the quote test file
stat
:
path={{output_dir}}/test_quoting.txt
register
:
result
-
name
:
assert test md5 matches after backref line was replaced
assert
:
that
:
-
"
result.stat.md5
==
'fbe9c4ba2490f70eb1974ce31ec4a39f'"
###################################################################
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