Skip to content

UTF-16 files are silently excluded by binary detection #30

Description

@kcaswick-pierce

Describe the bug
Files encoded in UTF-16LE (common default output for many Windows/PowerShell and Microsoft developer tools) are silently treated as binary files and omitted from output. Because UTF-16LE strings alternate text characters with null bytes (0x00), naive binary detection flags them as binary assets.

On the original file from the Microsoft tool, file reports:
HTML document, Unicode text, UTF-16, little-endian text, with CRLF line terminators

To Reproduce

Steps to reproduce the behavior:

  1. Create a UTF-16LE file with BOM:

    python3 -c "open('sample_utf16.htm', 'wb').write('<!DOCTYPE html>\r\n<html>\r\n<body>\r\n<p>Hello World</p>\r\n</body>\r\n</html>\r\n'.encode('utf-16'))"

    (Running file sample_utf16.htm confirms: sample_utf16.htm: HTML document, Unicode text, UTF-16, little-endian text, with CRLF line terminators)

  2. Run:

    code2prompt --tokens --path sample_utf16.htm
  3. Output shows no file data:

# Table of Contents


📋 Content copied to clipboard successfully.

✨ Token count: 5

  1. Clipboard contains only:
# Table of Contents

Expected behavior

  • Preferred: The encoding is automatically detected, opened using that encoding, and treated as a text file.
  • Acceptable: A warning is printed to stderr specifying which file was skipped and why (e.g., Skipping sample_utf16.htm: detected as binary).

Desktop:

  • OS: Microsoft Windows 11 (reproducible cross-platform via the command above)
  • code2prompt version 0.8.1

Activity

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions