Skip to content

Commit

Permalink
Merge pull request #45029 from jonathanhefner/fix-extract_dimensions-…
Browse files Browse the repository at this point in the history
…regexp

Escape literal dot in regular expression
  • Loading branch information
byroot committed May 9, 2022
2 parents 05a6176 + fe24f58 commit dd0b302
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions actionview/lib/action_view/helpers/asset_tag_helper.rb
Expand Up @@ -527,9 +527,9 @@ def resolve_asset_source(asset_type, source, skip_pipeline)

def extract_dimensions(size)
size = size.to_s
if /\A(\d+|\d+.\d+)x(\d+|\d+.\d+)\z/.match?(size)
if /\A\d+(?:\.\d+)?x\d+(?:\.\d+)?\z/.match?(size)
size.split("x")
elsif /\A(\d+|\d+.\d+)\z/.match?(size)
elsif /\A\d+(?:\.\d+)?\z/.match?(size)
[size, size]
end
end
Expand Down
4 changes: 4 additions & 0 deletions actionview/test/template/asset_tag_helper_test.rb
Expand Up @@ -230,6 +230,8 @@ def content_security_policy_nonce
%(image_tag("platinum.png", :size => "4.9x20")) => %(<img height="20" src="/images/platinum.png" width="4.9" />),
%(image_tag("platinum.png", "size" => "4.9x20")) => %(<img height="20" src="/images/platinum.png" width="4.9" />),
%(image_tag("error.png", "size" => "45 x 70")) => %(<img src="/images/error.png" />),
%(image_tag("error.png", "size" => "1,024x768")) => %(<img src="/images/error.png" />),
%(image_tag("error.png", "size" => "768x1,024")) => %(<img src="/images/error.png" />),
%(image_tag("error.png", "size" => "x")) => %(<img src="/images/error.png" />),
%(image_tag("google.com.png")) => %(<img src="/images/google.com.png" />),
%(image_tag("slash..png")) => %(<img src="/images/slash..png" />),
Expand Down Expand Up @@ -312,6 +314,8 @@ def content_security_policy_nonce
%(video_tag("error.avi", "size" => "100")) => %(<video height="100" src="/videos/error.avi" width="100"></video>),
%(video_tag("error.avi", "size" => 100)) => %(<video height="100" src="/videos/error.avi" width="100"></video>),
%(video_tag("error.avi", "size" => "100 x 100")) => %(<video src="/videos/error.avi"></video>),
%(video_tag("error.avi", "size" => "1,024x768")) => %(<video src="/videos/error.avi"></video>),
%(video_tag("error.avi", "size" => "768x1,024")) => %(<video src="/videos/error.avi"></video>),
%(video_tag("error.avi", "size" => "x")) => %(<video src="/videos/error.avi"></video>),
%(video_tag("http://media.rubyonrails.org/video/rails_blog_2.mov")) => %(<video src="http://media.rubyonrails.org/video/rails_blog_2.mov"></video>),
%(video_tag("//media.rubyonrails.org/video/rails_blog_2.mov")) => %(<video src="//media.rubyonrails.org/video/rails_blog_2.mov"></video>),
Expand Down

0 comments on commit dd0b302

Please sign in to comment.