Skip to content

Commit 42bf019

Browse files
Address copilot feedback
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 0c11eaa commit 42bf019

3 files changed

Lines changed: 33 additions & 9 deletions

File tree

app/controllers/thirdiron_controller.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'uri'
2+
13
class ThirdironController < ApplicationController
24
layout false
35

@@ -14,12 +16,27 @@ def browzine
1416
return unless ThirdIron.enabled? && params[:issn].present?
1517

1618
@browzine = Browzine.lookup(issn: params[:issn])
17-
@full_record_url = params[:full_record_url]
19+
@full_record_url = safe_full_record_url(params[:full_record_url])
1820
end
1921

2022
private
2123

2224
def expected_params?
2325
params[:type].present? && params[:identifier].present?
2426
end
27+
28+
def safe_full_record_url(url)
29+
return nil unless url.is_a?(String)
30+
31+
url = url.strip
32+
return nil if url.blank?
33+
34+
parsed = URI.parse(url)
35+
return nil unless parsed.is_a?(URI::HTTP) || parsed.is_a?(URI::HTTPS)
36+
return nil if parsed.host.blank?
37+
38+
parsed.to_s
39+
rescue URI::InvalidURIError, ArgumentError
40+
nil
41+
end
2542
end
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
<% if ThirdIron.enabled? && @browzine.present? %>
2-
<%= link_to 'Full-text options', @full_record_url, class: 'button libkey-link', data: { matomo_seen: "Results, Full-text Options Link Seen, Tab: {{getActiveTabName}}", matomo_click: "Results, Full-text Options Link Engaged, Link: {{getElementText}}", content_piece: 'Full-text options' } %>
3-
4-
<% if @browzine[:browzine_link].present? %>
5-
<div class="libkey-actions">
6-
<%= link_to @browzine[:browzine_link][:text], @browzine[:browzine_link][:link], class: 'libkey-link', data: { matomo_seen: "Results, Browzine Link Seen, Tab: {{getActiveTabName}}", matomo_click: "Results, Browzine Link Engaged, Link: {{getElementText}}", content_piece: @browzine[:browzine_link][:text] } %>
7-
</div>
1+
<% if ThirdIron.enabled? && @browzine.present? && @browzine[:browzine_link].present? %>
2+
<% if @full_record_url.present? %>
3+
<%= link_to 'Full-text options', @full_record_url, class: 'button libkey-link', data: { matomo_seen: "Results, Full-text Options Link Seen, Tab: {{getActiveTabName}}", matomo_click: "Results, Full-text Options Link Engaged, Link: {{getElementText}}", content_piece: 'Full-text options' } %>
84
<% end %>
5+
6+
<div class="libkey-actions">
7+
<%= link_to @browzine[:browzine_link][:text], @browzine[:browzine_link][:link], class: 'libkey-link', data: { matomo_seen: "Results, Browzine Link Seen, Tab: {{getActiveTabName}}", matomo_click: "Results, Browzine Link Engaged, Link: {{getElementText}}", content_piece: @browzine[:browzine_link][:text] } %>
8+
</div>
99
<% end %>

test/controllers/thirdiron_controller_test.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ class ThirdironControllerTest < ActionDispatch::IntegrationTest
111111
get '/browzine?issn=1546170X'
112112

113113
assert_response :success
114-
assert_select 'a.button', { count: 1 }
114+
115+
# Only browzine link, no button since no full_record_url provided
116+
assert_select 'a.button', { count: 0 }
117+
assert_select 'a.libkey-link', { count: 1 }
115118
end
116119
end
117120

@@ -120,6 +123,10 @@ class ThirdironControllerTest < ActionDispatch::IntegrationTest
120123
get '/browzine?issn=1546170X&full_record_url=https://example.com/full-record'
121124

122125
assert_response :success
126+
127+
# Button (Full-text options) and browzine link both have libkey-link class
128+
assert_select 'a.button', { count: 1 }
129+
assert_select 'a.button[href="https://example.com/full-record"]'
123130
assert_select 'a.libkey-link', { count: 2 }
124131
end
125132
end

0 commit comments

Comments
 (0)