Skip to content

Comments

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

@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
@Saidbek Saidbek force-pushed the improve-windows-filename-handling branch from d8371bf to 1642622 Compare February 18, 2026 19:20
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 1642622 to e2d08d6 Compare February 18, 2026 19:20
@larskanis
Copy link
Contributor

This LGTM now, ready to be merged. I tested Windows gem install:

$ gem inst crono:2.0.1
ERROR:  While executing gem ... (Gem::Package::InvalidWindowsFileNameError)
    The gem contains a file 'spec/internal/:memory' with characters in its name that are not allowed on Windows. This is a problem with the 'crono-2.0.1' gem, not Rubygems. Please report this issue to the gem author. (Gem::Package::InvalidWindowsFileNameError)
        C:/Ruby40-arm/lib/ruby/site_ruby/4.0.0/rubygems/package.rb:446:in 'block (2 levels) in Gem::Package#extract_tar_gz'
[...]
       C:/Ruby40-arm/bin/gem:12:in '<main>'

Linux gem install:

$ gem inst crono:2.0.1
Successfully installed crono-2.0.1
Parsing documentation for crono-2.0.1
Done installing documentation for crono after 0 seconds
1 gem installed

Linux gem build:

$ gem build crono.gemspec
WARNING:  make sure you specify the oldest ruby version constraint (like ">= 3.0") that you want your gem to support by setting the `required_ruby_version` gemspec attribute
WARNING:  See https://guides.rubygems.org/specification-reference/ for help
Enter PEM pass phrase:
WARNING:  filename 'spec/internal/:memory' contains characters that are invalid on Windows (e.g., colons). This gem may fail to install on Windows.
  Successfully built RubyGem
  Name: crono
  Version: 2.0.1
  File: crono-2.0.1.gem

And I did run the tests on Windows and Linux. All looks good now.

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