Skip to content

Commit 95b6bfb

Browse files
hsbtclaude
andcommitted
Coerce the post-install message to a String before sanitizing
post_install_message may be a non-String such as an array, so call to_s before clean_text to avoid raising during install. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 0db489f commit 95b6bfb

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

lib/rubygems/installer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ def install
299299

300300
File.chmod(dir_mode, gem_dir) if dir_mode
301301

302-
say clean_text(spec.post_install_message) if options[:post_install_message] && !spec.post_install_message.nil?
302+
say clean_text(spec.post_install_message.to_s) if options[:post_install_message] && !spec.post_install_message.nil?
303303

304304
Gem::Specification.add_spec(spec) unless @install_dir
305305

test/rubygems/test_gem_installer.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,6 +1498,22 @@ def test_install_sanitizes_post_install_message
14981498
refute_match(/\e\]2;pwn/, @ui.output)
14991499
end
15001500

1501+
def test_install_handles_non_string_post_install_message
1502+
# post_install_message may be a non-String (the gemspec schema allows an
1503+
# array), so sanitizing must not assume it responds to gsub.
1504+
@spec = setup_base_spec
1505+
@spec.post_install_message = %w[one two]
1506+
1507+
installer = Gem::Installer.for_spec @spec, post_install_message: true
1508+
installer.gem_home = @gemhome
1509+
1510+
use_ui @ui do
1511+
installer.install
1512+
end
1513+
1514+
assert_match(/one/, @ui.output)
1515+
end
1516+
15011517
def test_install_extension_dir
15021518
gemhome2 = "#{@gemhome}2"
15031519

0 commit comments

Comments
 (0)