@@ -6,18 +6,35 @@ module OAuth2
66 auth_sanitizer_spec = Gem . loaded_specs [ "auth-sanitizer" ]
77 unless auth_sanitizer_spec && auth_sanitizer_requirement . satisfied_by? ( auth_sanitizer_spec . version )
88 # :nocov:
9- auth_sanitizer_spec = Gem ::Specification . find_by_name ( "auth-sanitizer" , auth_sanitizer_requirement )
9+ begin
10+ auth_sanitizer_spec = Gem ::Specification . find_by_name ( "auth-sanitizer" , auth_sanitizer_requirement )
11+ rescue Gem ::MissingSpecError
12+ auth_sanitizer_spec = nil
13+ end
1014 # :nocov:
1115 end
1216
13- auth_sanitizer_loader_path = File . join (
14- auth_sanitizer_spec . full_gem_path ,
15- "lib/auth_sanitizer/loader.rb"
16- )
17- unless File . file? ( auth_sanitizer_loader_path )
17+ auth_sanitizer_loader_path = if auth_sanitizer_spec
18+ File . join ( auth_sanitizer_spec . full_gem_path , "lib/auth_sanitizer/loader.rb" )
19+ end
20+ unless auth_sanitizer_loader_path && File . file? ( auth_sanitizer_loader_path )
21+ auth_sanitizer_loader_path = Gem . find_files ( "auth_sanitizer/loader.rb" ) . find do |path |
22+ version_path = File . expand_path ( "../auth/sanitizer/version.rb" , File . dirname ( path ) )
23+ next false unless File . file? ( version_path )
24+
25+ version_source = File . read ( version_path )
26+ # Gem.find_files resolves loaders from $LOAD_PATH without exposing gemspec
27+ # metadata, so validate the adjacent version file before evaluating the
28+ # loader. This is intentionally limited to auth-sanitizer's VERSION file.
29+ version_match = version_source . match ( /VERSION\s *=\s *(["'])([^"']+)\1 / )
30+ version_match && auth_sanitizer_requirement . satisfied_by? ( Gem ::Version . new ( version_match [ 2 ] ) )
31+ end
32+ end
33+
34+ unless auth_sanitizer_loader_path && File . file? ( auth_sanitizer_loader_path )
1835 # :nocov:
1936 raise LoadError , "oauth2 requires auth-sanitizer #{ auth_sanitizer_requirement } ; " \
20- "loader not found at #{ auth_sanitizer_loader_path } "
37+ "loader not found in installed gems or on $LOAD_PATH "
2138 # :nocov:
2239 end
2340
0 commit comments