Skip to content

Commit

Permalink
Remove trailing newlines from the output of LinkComponent (#1183)
Browse files Browse the repository at this point in the history
* Remove trailing newlines from the output of LinkComponent

* Fix HTML escaping issue
  • Loading branch information
camertron authored Jun 2, 2022
1 parent a982a3b commit 84b9e4e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/sour-berries-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/view-components': patch
---

Remove trailing newlines from the output of LinkComponent
1 change: 0 additions & 1 deletion app/components/primer/link_component.erb

This file was deleted.

6 changes: 6 additions & 0 deletions app/components/primer/link_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,11 @@ def initialize(href: nil, tag: DEFAULT_TAG, scheme: DEFAULT_SCHEME, muted: false
def before_render
raise ArgumentError, "href is required when using <a> tag" if @system_arguments[:tag] == :a && @system_arguments[:href].nil? && !Rails.env.production?
end

def call
render(Primer::BaseComponent.new(**@system_arguments)) do
content.to_s + tooltip.to_s
end
end
end
end
6 changes: 6 additions & 0 deletions test/components/link_component_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ def test_renders_no_additional_whitespace
assert_text(/^content$/)
end

def test_renders_without_trailing_newline
render_inline(Primer::LinkComponent.new(href: "http://joe-jonas-shirtless.com")) { "content" }

refute @rendered_content.end_with?("\n")
end

def test_renders_as_a_link
render_inline(Primer::LinkComponent.new(href: "http://google.com")) { "content" }

Expand Down

0 comments on commit 84b9e4e

Please sign in to comment.