-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Windows: UCS-2 aka UTF-16 textfiles are treated as binary files by file.replace #52793
Comments
Might even be possible to determine the encoding automatically. At least the
|
The following, slightly modified version of above sample code does this, using libmagic Python bindings (aka. python3-magic):
|
I, for one, would like to overhaul a lot of how we handle file/stream encodings, with the ability to specify all the things (and perhaps default to utf-8, if possible). |
Sounds good, although I'd consider this a bug. Anyway, here's a version of the sample code using chardet, which might be more platform independent:
|
Any news on this bug? |
Nothing currently - we're currently pushing hard to stabilize our test suites/pipeline, but this is definitely on my radar. My personal opinion is that Salt should never assume encoding (though right now we assume utf-8, if we assume anything). I think I'd welcome a PR that adds an |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue. |
Ping. |
Thank you for updating this issue. It is no longer marked as stale. |
file.managed seems to have a similar issue, trying to manage a file encoded utf-16 LE (xml export from Windows Task Scheduler), added some Jinja to templatize the file, but is treated as binary. not replacing jinja by defaults values
This causes the file to be treated as binary and Jinja does not get replaced.
As soon encoding of the file is changed to utf-8, the file is replaced by text file and jinja values are replaced. |
Description of Issue
When trying to run
file.replace
on a UCS-2 encoded file on Windows, it errors out with the following message:Instead of doing this, file.replace should support specifying the correct encoding for the file, for example:
The following Python(3) example does this (and even automatically writes a BOM):
Versions Report
The text was updated successfully, but these errors were encountered: