Skip to content

Improve handling of paths with invalid Windows characters#9276

Open
Saidbek wants to merge 3 commits intoruby:masterfrom
Saidbek:improve-windows-filename-handling
Open

Improve handling of paths with invalid Windows characters#9276
Saidbek wants to merge 3 commits intoruby:masterfrom
Saidbek:improve-windows-filename-handling

Conversation

@Saidbek
Copy link

@Saidbek Saidbek commented Jan 29, 2026

What is your fix for the problem, implemented in this PR?

Fixes #7681

Windows doesn't allow certain characters in filenames (e.g., colons) that are valid on Unix. When gems contain files with these characters, installation fails on Windows with cryptic Errno::EINVAL errors.

This PR adds validation and directs users to report issues to gem authors instead.

  • Add InvalidFileNameError with user-friendly messages
  • Validate filenames during gem extraction on Windows
  • Warn developers when building gems with invalid filenames

Make sure the following tasks are checked

Add validation and clear error messages for gems with filenames containing
invalid Windows characters (e.g., colons), directing users to report issues
to gem authors instead of RubyGems.
@Saidbek Saidbek force-pushed the improve-windows-filename-handling branch from bbb7488 to c9af675 Compare February 3, 2026 09:20
@Saidbek Saidbek force-pushed the improve-windows-filename-handling branch from d8abe69 to a8dfff3 Compare February 9, 2026 06:42
@Saidbek Saidbek force-pushed the improve-windows-filename-handling branch from f92a344 to d8371bf Compare February 13, 2026 07:07
# Note: Colons are only valid as drive letter separators (e.g., C:), not in filenames.

def invalid_windows_filename?(filename) # :nodoc:
return false unless Gem.win_platform?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This disables the invalid character check on other platforms than Windows. So the intention to warn authors on other systems doesn't work. It warns only on Windows.

full_name = entry.full_name
next unless File.fnmatch pattern, full_name, File::FNM_DOTMATCH

if invalid_windows_filename?(full_name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The platform check should be here:

        if Gem.win_platform? && invalid_windows_filename?(full_name)

end

def test_build_warns_on_invalid_windows_filename
pend "Windows filename validation only applies on Windows" unless Gem.win_platform?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be the other way around:

pend "Windows filename validation only applies on non-Windows" if Gem.win_platform?

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve handling of paths with colons (allowed on Unix, disallowed on Windows)

4 participants