From 740c520b332ee0285c56529399064651dc6e5952 Mon Sep 17 00:00:00 2001 From: kares Date: Thu, 15 Oct 2026 11:12:01 +0200 Subject: [PATCH] [fix] decode file lock URLs with spaces (#114) we're getting classloader files as percent-encoded `uri:file:` covers loading Jars.lock from a dir whose name contains a space --- lib/jars/lock.rb | 4 +++- specs/classpath_spec.rb | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/jars/lock.rb b/lib/jars/lock.rb index c4fad5e..2eec475 100644 --- a/lib/jars/lock.rb +++ b/lib/jars/lock.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'jars/maven_exec' +require 'uri' module Jars class JarDetails < Array @@ -49,7 +50,8 @@ def path class Lock def initialize(file) - @file = file + # JRuby treats percent escapes literally in uri:file paths + @file = file.start_with?('uri:file:') ? URI::DEFAULT_PARSER.unescape(file) : file end def process(scope) diff --git a/specs/classpath_spec.rb b/specs/classpath_spec.rb index a2eee99..adfacbd 100644 --- a/specs/classpath_spec.rb +++ b/specs/classpath_spec.rb @@ -3,6 +3,7 @@ require File.expand_path('setup', File.dirname(__FILE__)) require 'yaml' +require 'tmpdir' module Helper def self.prepare!(array) @@ -207,6 +208,20 @@ def self.prepare(array) _(Helper.prepare(subject.classpath(:runtime))).must_equal Helper.prepare(lock_expected_runtime) end + it 'processes classloader Jars.lock URLs with spaces in the path' do + Dir.mktmpdir do |root| + dir = File.join(root, 'jar dependencies') + Dir.mkdir(dir) + lock = File.join(dir, 'Jars.lock') + File.write(lock, "org.slf4j:slf4j-simple:1.6.6:compile:\n") + url = "uri:file:#{URI::DEFAULT_PARSER.escape(lock)}" + + _(Jars::Classpath.new(nil, url).classpath).must_equal [ + File.join(Jars.home, 'org/slf4j/slf4j-simple/1.6.6/slf4j-simple-1.6.6.jar') + ] + end + end + it 'processes Jars.lock and block loading of jars' do subject.instance_variable_set(:@deps, jars_no_jline_lock)