Skip to content

Commit 071cd37

Browse files
author
Nick Veys
committed
Making sure URIs are escaped to handle ugly paths
1 parent 3bd038a commit 071cd37

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

lib/metric_fu/formatter/html.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def open_in_browser?
8888
# The directory path where the 'index.html' we want to open is
8989
# stored
9090
def show_in_browser(dir)
91-
uri = URI.join("file://#{dir}/", 'index.html')
91+
uri = URI.join(URI.escape("file://#{dir}/"), 'index.html')
9292
Launchy.open(uri) if open_in_browser?
9393
end
9494
end

spec/metric_fu/formatter/html_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def directory(name)
8787
it "can open the results in the browser" do
8888
formatter = MetricFu::Formatter::HTML.new
8989
path = MetricFu.run_path.join(directory('output_directory'))
90-
uri = URI.join("file://#{path}/", 'index.html')
90+
uri = URI.join(URI.escape("file://#{path}/"), 'index.html')
9191
expect(Launchy).to receive(:open).with(uri)
9292
formatter.finish
9393
formatter.display_results
@@ -140,7 +140,7 @@ def directory(name)
140140
it "can open the results in the browser from the custom output directory" do
141141
formatter = MetricFu::Formatter::HTML.new(output: @output)
142142
path = MetricFu.run_path.join("#{directory('base_directory')}/#{@output}")
143-
uri = URI.join("file://#{path}/", 'index.html')
143+
uri = URI.join(URI.escape("file://#{path}/"), 'index.html')
144144
expect(Launchy).to receive(:open).with(uri)
145145
formatter.finish
146146
formatter.display_results

spec/usage_test_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@
7070
expect(test_result.success).to eq(false)
7171
end
7272
specify 'succeeds when the code exits with a zero exit status' do
73-
code = "sh #{fixtures_path.join('exit0.sh').to_path}"
73+
code = "sh '#{fixtures_path.join('exit0.sh').to_path}'"
7474
test_result = SnippetRunner.new(code, 'sh').run_code
7575
expect(test_result.captured_output).to match("exit status 0")
7676
expect(test_result.success).to eq(true)
7777
end
7878
specify 'fails when the code exits with a non-zero exit status' do
79-
code = "sh #{fixtures_path.join('exit1.sh').to_path}"
79+
code = "sh '#{fixtures_path.join('exit1.sh').to_path}'"
8080
test_result = SnippetRunner.new(code, 'sh').run_code
8181
expect(test_result.captured_output).to match("exit status 1")
8282
expect(test_result.success).to eq(false)

0 commit comments

Comments
 (0)