Skip to content

Improve handling of paths with invalid Windows characters - #9276

Merged
hsbt merged 4 commits into
ruby:masterfrom
Saidbek:improve-windows-filename-handling
Oct 1, 2026
Merged

hsbt merged 4 commits into
ruby:masterfrom
Saidbek:improve-windows-filename-handling

Conversation

@Saidbek

@Saidbek Saidbek commented Jan 29, 2026 •

Copy link
Copy Markdown
Contributor

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
Comment thread lib/rubygems/package.rb Outdated
Comment thread lib/rubygems/package.rb Outdated
@Saidbek
Saidbek force-pushed the improve-windows-filename-handling branch from d8abe69 to a8dfff3 Compare February 9, 2026 06:42
Comment thread lib/rubygems/package.rb Outdated
Comment thread lib/rubygems/package.rb
@Saidbek
Saidbek force-pushed the improve-windows-filename-handling branch from f92a344 to d8371bf Compare February 13, 2026 07:07
Comment thread lib/rubygems/package.rb Outdated
Comment thread lib/rubygems/package.rb Outdated
Comment thread test/rubygems/test_gem_package.rb Outdated
@Saidbek
Saidbek force-pushed the improve-windows-filename-handling branch 2 times, most recently from 1642622 to e2d08d6 Compare February 18, 2026 19:20
@larskanis

Copy link
Copy Markdown
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.

@larskanis larskanis mentioned this pull request Mar 5, 2026
2 of 4 tasks
@hsbt
hsbt force-pushed the improve-windows-filename-handling branch from e2d08d6 to ea105d6 Compare May 28, 2026 00:59
@hsbt
hsbt enabled auto-merge October 1, 2026 03:13
@hsbt
hsbt force-pushed the improve-windows-filename-handling branch from fff030b to 2c3c054 Compare October 1, 2026 03:17
Saidbek and others added 4 commits October 1, 2026 12:34
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.
Bundler and `gem install` only handle Gem::InstallError as an install failure, so this error fell through to Bundler's issue report template and to the generic crash handler of `gem`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hsbt
hsbt force-pushed the improve-windows-filename-handling branch from 2c3c054 to a822203 Compare October 1, 2026 03:35
@hsbt
hsbt merged commit 788d6ba into ruby:master Oct 1, 2026
130 of 132 checks passed
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