Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid checking defined?(@html_safe) on Ruby 3+ #45620

Merged
merged 1 commit into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,9 @@ def %(args)
self.class.new(super(escaped_args))
end

def html_safe?
defined?(@html_safe) && @html_safe
end
attr_reader :html_safe
alias_method :html_safe?, :html_safe
remove_method :html_safe

def to_s
self
Expand Down
7 changes: 7 additions & 0 deletions activesupport/test/safe_buffer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ def test_titleize
assert_not_predicate @buffer.dup, :html_safe?
end

test "Can call html_safe on a safe buffer" do
@buffer = "hello".html_safe
extra_safe = @buffer.html_safe
assert_equal "hello", extra_safe
assert_predicate extra_safe, :html_safe?
end

test "Should return safe buffer when added with another safe buffer" do
clean = "<script>".html_safe
result_buffer = @buffer + clean
Expand Down