52 lines
1.6 KiB
Diff
52 lines
1.6 KiB
Diff
|
|
From 3cf23c3f891e2e81c977ea4ab83b62bc2a444b70 Mon Sep 17 00:00:00 2001
|
||
|
|
From: Akira Matsuda <ronnie@dio.jp>
|
||
|
|
Date: Thu, 5 Jan 2023 05:25:37 +0900
|
||
|
|
Subject: [PATCH] Implement SafeBuffer#bytesplice
|
||
|
|
|
||
|
|
---
|
||
|
|
.../core_ext/string/output_safety.rb | 4 +++
|
||
|
|
.../test/core_ext/string_ext_test.rb | 30 +++++++++++++++++++
|
||
|
|
2 files changed, 34 insertions(+)
|
||
|
|
|
||
|
|
diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb
|
||
|
|
index a51f2f64cbe27..c436821c94a0b 100644
|
||
|
|
--- a/activesupport/test/core_ext/string_ext_test.rb
|
||
|
|
+++ b/activesupport/test/core_ext/string_ext_test.rb
|
||
|
|
@@ -987,6 +987,36 @@ def to_s
|
||
|
|
assert_predicate string, :html_safe?
|
||
|
|
end
|
||
|
|
|
||
|
|
+ if "".respond_to?(:bytesplice)
|
||
|
|
+ test "Bytesplicing safe into safe yields safe" do
|
||
|
|
+ string = "hello".html_safe
|
||
|
|
+ string.bytesplice(0, 0, "<b>".html_safe)
|
||
|
|
+
|
||
|
|
+ assert_equal "<b>hello", string
|
||
|
|
+ assert_predicate string, :html_safe?
|
||
|
|
+
|
||
|
|
+ string = "hello".html_safe
|
||
|
|
+ string.bytesplice(0..1, "<b>".html_safe)
|
||
|
|
+
|
||
|
|
+ assert_equal "<b>llo", string
|
||
|
|
+ assert_predicate string, :html_safe?
|
||
|
|
+ end
|
||
|
|
+
|
||
|
|
+ test "Bytesplicing unsafe into safe yields escaped safe" do
|
||
|
|
+ string = "hello".html_safe
|
||
|
|
+ string.bytesplice(1, 0, "<b>")
|
||
|
|
+
|
||
|
|
+ assert_equal "h<b>ello", string
|
||
|
|
+ assert_predicate string, :html_safe?
|
||
|
|
+
|
||
|
|
+ string = "hello".html_safe
|
||
|
|
+ string.bytesplice(1..2, "<b>")
|
||
|
|
+
|
||
|
|
+ assert_equal "h<b>lo", string
|
||
|
|
+ assert_predicate string, :html_safe?
|
||
|
|
+ end
|
||
|
|
+ end
|
||
|
|
+
|
||
|
|
test "emits normal string yaml" do
|
||
|
|
assert_equal "foo".to_yaml, "foo".html_safe.to_yaml(foo: 1)
|
||
|
|
end
|