Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/irb/command/load.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def execute(arg)
def execute_internal(file_name = nil)
raise_cmd_argument_error unless file_name

rex = Regexp.new("#{Regexp.quote(file_name)}(\.o|\.rb)?")
rex = Regexp.new("\\A#{Regexp.escape(file_name)}(?:\\.o|\\.rb)?\\z")
return false if $".find{|f| f =~ rex}

case file_name
Expand Down
15 changes: 15 additions & 0 deletions test/irb/test_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,21 @@ def test_irb_load_without_argument
assert_empty err
assert_match(/Please specify the file name./, out)
end

def test_irb_require_file_matches_exact_name
File.write("#{@tmpdir}/foo.rb", "'foo_loaded'\n")
File.write("#{@tmpdir}/foo2.rb", "'foo2_loaded'\n")

out, err = execute_lines(
"$LOAD_PATH.unshift '#{@tmpdir}'\n",
"irb_require 'foo'\n",
"irb_require 'foo2'\n",
)

assert_empty(err)
assert_match(/foo_loaded/, out)
assert_match(/foo2_loaded/, out)
end
end

class WorkspaceCommandTestCase < CommandTestCase
Expand Down