Skip to content

Commit 3cf9b50

Browse files
chrismyttonOliver Denman
authored and
Oliver Denman
committed
Add decorator to strip session info from URLs
Following links with session information doesn't work correctly with Ruby's open-uri, so rather than using Capybara this simply strips away the session information.
1 parent 9f6a183 commit 3cf9b50

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
require 'uri'
3+
4+
class RemoveSessionFromUrlDecorator < Scraped::Response::Decorator
5+
# Remove session information from urls
6+
def body
7+
noko = Nokogiri::HTML(super)
8+
noko.css('a[href*="_piref"]').each do |a|
9+
uri = URI.parse(a[:href])
10+
uri.query = uri.query.gsub(/_piref[\d_]+\./, '')
11+
a[:href] = uri.to_s
12+
end
13+
noko.to_s
14+
end
15+
end

0 commit comments

Comments
 (0)