[BUG] file.replace open file in binary mode Windows
Description File replace opens file in binary mode "rb" to see if their is a match first, which results in patterns with start of line and end of line not matching on windows. The code which is not reach, opens the file again without binary on. May also impact utf-8 processing of non ASCII chars.
Thoughts file module.,does it need output encoding option defaulting to the platforms encoding utf-8 or mbcs etc. Does it need a way to enforce a line feed type.
Setup On Windows Salt 3006.4
On windows create a file with DOS line endings abc.txt but the line "something=" in line in the middle of the file.
replace_dos_file_line:
file.replace:
-name: 'abc.txt'
- pattern: '^(.*)something=\d+'
- repl: '\1something=123'
- show_changes: True
- flags: ['IGNORECASE']Please be as specific as possible and give set-up details.
- on-prem machine
- VM (Virtualbox, KVM, etc. please specify)
- VM running on a cloud service, please be explicit and add details
- container (Kubernetes, Docker, containerd, etc. please specify)
- or a combination, please be explicit
- jails if it is FreeBSD
- classic packaging
- onedir packaging
- used bootstrap to install
Steps to Reproduce the behavior See example state above
Expected behavior That start of line should work in pattern matching
Versions Report
Windows Salt 3006.4
with with salt.utils.files.fopen(path, mode="rb", buffering=bufsize)
Also note that their is a check to see if a file is binary or not, utf-8 file may come across as being binary.
Additional context Add any other context about the problem here.
Sample file abc.txt
one two
three
four
something=111111
ten
nineSource: saltstack/salt