Search for (but do not include) CRLF line ending

When searching for a line in a file that has CRLF line endings, the
normal $ regex will not match a line. With this change, we will match on
but not include LF, CRLF, and the end of a file.
This commit is contained in:
Daniel A. Wozniak 2018-08-13 12:35:01 -07:00
parent af6ec1dce2
commit 0dca634e3c
No known key found for this signature in database
GPG key ID: 166B9D2C06C82D61

View file

@ -2111,7 +2111,7 @@ def replace(path,
if prepend_if_not_found or append_if_not_found:
# Search for content, to avoid pre/appending the
# content if it was pre/appended in a previous run.
if re.search(salt.utils.to_bytes('^{0}$'.format(re.escape(content))),
if re.search(salt.utils.to_bytes('^{0}($|(?=\r\n))'.format(re.escape(content))),
r_data,
flags=flags_num):
# Content was found, so set found.