Skip to content

Discrepancy in "Find in Files": UTF-16 bug and missing report for skipped binary files #133

Description

@daddel80

Summary

As reported by @guy038 in the Notepad++ Community Forum, "Find in Files" (v6.0.0.36) returns significantly fewer matches than native Notepad++ and the Search++ plugin on identical searches.

Original forum thread: [Insert Link to Forum Post]
Follow-up post with both test cases: [Insert Link to Post 106204]

Test case 1: USB drive scan

Search: Fi, Regular expression + Match case enabled, filter *.*, entire drive (1,772 files).

Tool Matches Files
Notepad++ native 27,081 841
Search++ 27,081 841
MultiReplace Find in Files 18,767 726

Test case 2: E:\Test folder (7 files)

Same search, MultiReplace only, folder open in N++ with no session:

  • Find in Files: 83 hits in 3 files
  • Find in Docs: 372 hits in 7 files

Root causes (two separate issues)

1. Binary files skipped without UI feedback (by design, undocumented)
HiddenSciGuard::loadFile skips any file with a NUL byte in its first 8 KB and no BOM, the same heuristic grep uses. Native N++ and Search++ scan such files as raw bytes and count matches inside them (e.g. .exe, .dll, .pdf, .zip). This is likely the main driver of test case 1. Not a bug, but _skippedBinaryCount is tracked internally and never surfaced to the user.

  • Fix: show "N binary files skipped" in the result summary / dock header.

2. UTF-16 files mishandled in Find in Files (actual bug)
In the Find in Files loop, isLikelyBinary (MultiReplacePanel.cpp) flags any file containing a NUL byte anywhere in the buffer, including UTF-16 files with a BOM that loadFile deliberately let through. Those get searched as raw ANSI bytes, so Fi can never match F\0i\0. UTF-16 files without a BOM are separately caught by the binary skip in loadFile. Replace in Files does not have this flaw (decodes via Encoding::detectEncoding before searching), and Find in Docs works on buffers Notepad++ has already decoded, which is why results diverge between the three modes.

  • Fix: apply the same encoding detection Replace in Files uses before the binary heuristic in Find in Files.

Test case 2 most likely combines both causes (some of the 4 missing files binary-skipped, some UTF-16-miscounted) rather than being a clean example of #2 alone, to be confirmed once the test files are available.

Verification pending

@guy038 has offered to share the E:\Test folder contents. Will attach here and re-verify both fixes against it before closing.

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

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions