Skip to content

PowerShell files encoding issue #1441

Closed

Description

@MBV21

For compatibility reasons, I use PowerShell v5.1 scripts, which by
default use the ANSI/Windows 1252 character encoding.

dnGrep does not detect these files using ANSI/W1252 and, when
making text substitutions, the files are saved using UTF-8.

For reference, WinMerge correctly detects the character encoding
in PowerShell files. It identifies .ps1 files when they are encoded in
ANSI (PS v5.1) and in UTF8 (PS v7).

Is it possible to implement a way to override character encoding
detection for file types?

Activity

  1. doug24 commented on Feb 26, 2026

    @doug24
    Contributor

    No, not by file type. You can override it for a search so all files found in the search would use the encoding you pick.

    Can you post a file here that has this problem? I'd like to see what is happening.

  2. MBV21 commented on Feb 26, 2026

    @MBV21
    Author

    Sure thing.

    PS1.zip

  3. MBV21 commented on Feb 26, 2026

    @MBV21
    Author

    Additional information.

    Image

    Image

  4. doug24 commented on Feb 26, 2026

    @doug24
    Contributor

    The automatic encoding detection returns Western European (ISO) cp28591 for the ANSI file. I think that is reasonable given the characters in the file. If it had contained the Euro sign (€), Trademark symbol (™), smart quotes (“ ”), curly apostrophes (‘ ’), en-dash (–), or em-dash (—), it would have returned cp1252. I didn't write the encoding detector, it is a library call. I don't know why it would prefer cp28591 over cp1252.

    Image

    The file is shown correctly in the results tree and preview window with cp28591 and with cp1252.

    Yes, there is a bug in the Replace preview code. It is not setting the encoding correctly when reading in the modified data for preview. But from what I see, the code that writes the output file (which is separate from the preview) is using the correct encoding and the output file is the same encoding as the input file.

    Image
  5. MBV21 commented on Feb 27, 2026

    @MBV21
    Author

    Thank you.

    dnGrep is an amazing tool.

  6. doug24 commented on Mar 11, 2026

    @doug24
    Contributor

    Fix is included in the v4.7.10 release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions