Skip to content

Commit acffb99

Browse files
authored
Merge pull request rails#53426 from jhawthorn/security_forward_ports
Security release forward ports to newer branches
2 parents c8ad2b2 + 6fdabdf commit acffb99

File tree

7 files changed

+63
-14
lines changed

7 files changed

+63
-14
lines changed

actionmailer/lib/action_mailer/mail_helper.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,18 @@ def block_format(text)
2525
}.join("\n\n")
2626

2727
# Make list points stand on their own line
28-
formatted.gsub!(/[ ]*([*]+) ([^*]*)/) { " #{$1} #{$2.strip}\n" }
29-
formatted.gsub!(/[ ]*([#]+) ([^#]*)/) { " #{$1} #{$2.strip}\n" }
28+
output = +""
29+
splits = formatted.split(/(\*+|\#+)/)
30+
while line = splits.shift
31+
if line.start_with?("*", "#") && splits.first&.start_with?(" ")
32+
output.chomp!(" ") while output.end_with?(" ")
33+
output << " #{line} #{splits.shift.strip}\n"
34+
else
35+
output << line
36+
end
37+
end
3038

31-
formatted
39+
output
3240
end
3341

3442
# Access the mailer instance.

actionmailer/test/mail_helper_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,17 @@ def test_use_cache
121121
assert_equal "Greetings from a cache helper block", mail.body.encoded
122122
end
123123
end
124+
125+
def helper
126+
Object.new.extend(ActionMailer::MailHelper)
127+
end
128+
129+
def test_block_format
130+
assert_equal " * foo\n", helper.block_format(" * foo")
131+
assert_equal " * foo\n", helper.block_format(" * foo")
132+
assert_equal " * foo\n", helper.block_format("* foo")
133+
assert_equal " * foo\n*bar", helper.block_format("* foo*bar")
134+
assert_equal " * foo\n * bar\n", helper.block_format("* foo * bar")
135+
assert_equal " *", helper.block_format("* ")
136+
end
124137
end

actionpack/lib/action_controller/metal/http_authentication.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -513,14 +513,11 @@ def rewrite_param_values(array_params)
513513
array_params.each { |param| (param[1] || +"").gsub! %r/^"|"$/, "" }
514514
end
515515

516-
WHITESPACED_AUTHN_PAIR_DELIMITERS = /\s*#{AUTHN_PAIR_DELIMITERS}\s*/
517-
private_constant :WHITESPACED_AUTHN_PAIR_DELIMITERS
518-
519516
# This method takes an authorization body and splits up the key-value pairs by
520517
# the standardized `:`, `;`, or `\t` delimiters defined in
521518
# `AUTHN_PAIR_DELIMITERS`.
522519
def raw_params(auth)
523-
_raw_params = auth.sub(TOKEN_REGEX, "").split(WHITESPACED_AUTHN_PAIR_DELIMITERS)
520+
_raw_params = auth.sub(TOKEN_REGEX, "").split(AUTHN_PAIR_DELIMITERS).map(&:strip)
524521
_raw_params.reject!(&:empty?)
525522

526523
if !_raw_params.first&.start_with?(TOKEN_KEY)

actionpack/lib/action_dispatch/http/filter_parameters.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,17 @@ def parameter_filter_for(filters) # :doc:
6868
ActiveSupport::ParameterFilter.new(filters)
6969
end
7070

71-
KV_RE = "[^&;=]+"
72-
PAIR_RE = %r{(#{KV_RE})=(#{KV_RE})}
7371
def filtered_query_string # :doc:
74-
query_string.gsub(PAIR_RE) do |_|
75-
parameter_filter.filter($1 => $2).first.join("=")
72+
parts = query_string.split(/([&;])/)
73+
filtered_parts = parts.map do |part|
74+
if part.include?("=")
75+
key, value = part.split("=", 2)
76+
parameter_filter.filter(key => value).first.join("=")
77+
else
78+
part
79+
end
7680
end
81+
filtered_parts.join("")
7782
end
7883
end
7984
end

actionpack/lib/action_dispatch/http/filter_redirect.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,16 @@ def location_filter_match?
3737
def parameter_filtered_location
3838
uri = URI.parse(location)
3939
unless uri.query.nil? || uri.query.empty?
40-
uri.query.gsub!(FilterParameters::PAIR_RE) do
41-
request.parameter_filter.filter($1 => $2).first.join("=")
40+
parts = uri.query.split(/([&;])/)
41+
filtered_parts = parts.map do |part|
42+
if part.include?("=")
43+
key, value = part.split("=", 2)
44+
request.parameter_filter.filter(key => value).first.join("=")
45+
else
46+
part
47+
end
4248
end
49+
uri.query = filtered_parts.join("")
4350
end
4451
uri.to_s
4552
rescue URI::Error

actiontext/lib/action_text/plain_text_conversion.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ def plain_text_for_figcaption_node(node, index)
6565

6666
def plain_text_for_blockquote_node(node, index)
6767
text = plain_text_for_block(node)
68-
text.sub(/\A(\s*)(.+?)(\s*)\Z/m, '\1“\2”\3')
68+
return "“”" if text.blank?
69+
70+
text = text.dup
71+
text.insert(text.rindex(/\S/) + 1, "”")
72+
text.insert(text.index(/\S/), "“")
73+
text
6974
end
7075

7176
def plain_text_for_li_node(node, index)

actiontext/test/unit/plain_text_conversion_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@ class ActionText::PlainTextConversionTest < ActiveSupport::TestCase
1717
)
1818
end
1919

20+
test "<blockquote> tag with whitespace" do
21+
assert_converted_to(
22+
" “Hello world!” ",
23+
"<blockquote> Hello world! </blockquote>"
24+
)
25+
end
26+
27+
test "<blockquote> tag with only whitespace" do
28+
assert_converted_to(
29+
"“”",
30+
"<blockquote> </blockquote>"
31+
)
32+
end
33+
2034
test "<ol> tags are separated by two new lines" do
2135
assert_converted_to(
2236
"Hello world!\n\n1. list1\n\n1. list2\n\nHow are you?",

0 commit comments

Comments
 (0)