Skip to content

Commit

Permalink
Fix component wrapper rel option
Browse files Browse the repository at this point in the history
- code previously assumed that only one rel option would be passed, but you can have more than one in the attribute
- passing more than one previously caused an error even if all of the rels were valid, this change corrects that
  • Loading branch information
andysellick committed Jan 15, 2025
1 parent ac48418 commit 27c52d1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ def check_rel_is_valid(rel_attribute)
return if rel_attribute.blank?

options = %w[alternate author bookmark canonical dns-prefetch external expect help icon license manifest me modulepreload next nofollow noopener noreferrer opener pingback preconnect prefetch preload prerender prev privacy-policy search stylesheet tag terms-of-service]
unless options.include? rel_attribute
rel_array = rel_attribute.split(" ")
unless rel_array.all? { |r| options.include? r }
raise(ArgumentError, "rel attribute (#{rel_attribute}) is not recognised")
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,8 @@
end

it "accepts valid rel value" do
component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(rel: "nofollow")
expect(component_helper.all_attributes[:rel]).to eql("nofollow")
component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(rel: "nofollow noreferrer")
expect(component_helper.all_attributes[:rel]).to eql("nofollow noreferrer")
end

it "can set a rel, overriding a passed value" do
Expand Down

0 comments on commit 27c52d1

Please sign in to comment.