Skip to content

Commit

Permalink
ext: load C extension files from non-native gems via "require"
Browse files Browse the repository at this point in the history
and not "require relative"

Fixes #2300
  • Loading branch information
flavorjones committed Aug 3, 2021
1 parent 7776f51 commit 35f2f7a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/nokogiri/extension.rb
Expand Up @@ -2,6 +2,7 @@

# load the C or Java extension
begin
# native precompiled gems package shared libraries in <gem_dir>/lib/nokogiri/<ruby_version>
::RUBY_VERSION =~ /(\d+\.\d+)/
require_relative "#{Regexp.last_match(1)}/nokogiri"
rescue LoadError => e
Expand All @@ -22,5 +23,9 @@
EOM
raise e
end
require_relative "nokogiri"

# use "require" instead of "require_relative" because non-native gems will place C extension files
# in Gem::BasicSpecification#extension_dir after compilation (during normal installation), which
# is in $LOAD_PATH but not necessarily relative to this file (see #2300)
require "nokogiri/nokogiri"
end

0 comments on commit 35f2f7a

Please sign in to comment.