Merge pull request #51239 from garethgreenaway/51208_file_manage_escaped_double_quotes

[2018.3] Fixes to __build_parts in stringutils
This commit is contained in:
Thomas S Hatch 2019-01-22 15:17:48 -07:00 committed by GitHub
commit 1a2f680e1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 1 deletions

View File

@ -333,7 +333,9 @@ def build_whitespace_split_regex(text):
lexer = shlex.shlex(text)
lexer.whitespace_split = True
lexer.commenters = ''
if '\'' in text:
if r"'\"" in text:
lexer.quotes = ''
elif '\'' in text:
lexer.quotes = '"'
elif '"' in text:
lexer.quotes = '\''

View File

@ -0,0 +1,4 @@
/tmp/vimrc:
file.append:
- sources:
- salt://test/files/vimrc.stub

View File

@ -0,0 +1,8 @@
set number
syntax on
set paste
set ruler
if has("autocmd")
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif

View File

@ -2530,6 +2530,22 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
'',
]).encode('utf-8'))
def test_managed_file_issue_51208(self):
'''
Test to ensure we can handle a file with escaped double-quotes
'''
name = os.path.join(TMP, 'issue_51208.txt')
ret = self.run_state(
'file.managed', name=name, source='salt://issue-51208/vimrc.stub'
)
src = os.path.join(BASE_FILES, 'issue-51208', 'vimrc.stub')
with salt.utils.files.fopen(src, 'r') as fp_:
master_data = fp_.read()
with salt.utils.files.fopen(name, 'r') as fp_:
minion_data = fp_.read()
self.assertEqual(master_data, minion_data)
self.assertSaltTrueReturn(ret)
class BlockreplaceTest(ModuleCase, SaltReturnAssertsMixin):
marker_start = '# start'