From 7d96b603d3d7af20976198241d9c6abfea806f78 Mon Sep 17 00:00:00 2001 From: Maxwell Salzberg Date: Thu, 1 Sep 2011 10:13:47 -0700 Subject: [PATCH] fix bug where if youtube_maps or vimeo_maps were passed in as explicitly nil, the app would 500. #somethingididnotknow (Hash#fetch is kind of weird --- lib/diaspora/markdownify.rb | 4 ++-- spec/helpers/markdownify_helper_spec.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/diaspora/markdownify.rb b/lib/diaspora/markdownify.rb index e0b9f10f0..a5bed38e9 100644 --- a/lib/diaspora/markdownify.rb +++ b/lib/diaspora/markdownify.rb @@ -10,8 +10,8 @@ module Diaspora @newlines = options.fetch(:newlines, true) @specialchars = options.fetch(:specialchars, true) - @youtube_maps = options.fetch(:youtube_maps, {}) - @vimeo_maps = options.fetch(:vimeo_maps, {}) + @youtube_maps = options[:youtube_maps]||{} + @vimeo_maps = options[:vimeo_maps] || {} end def autolink(link, type) diff --git a/spec/helpers/markdownify_helper_spec.rb b/spec/helpers/markdownify_helper_spec.rb index eb9427cdc..8be02519f 100644 --- a/spec/helpers/markdownify_helper_spec.rb +++ b/spec/helpers/markdownify_helper_spec.rb @@ -7,6 +7,18 @@ require 'spec_helper' describe MarkdownifyHelper do describe "#markdownify" do + it 'does not error if youtube_maps in the hash is explicitly set to nil' do + expect{ + markdownify("http://www.youtube.com/watch?v=pZROlhHOvuo", :youtube_maps => nil) + }.should_not raise_error + end + + it 'does not error if youtube_maps in the hash is explicitly set to nil' do + expect{ + markdownify("http://vimeo.com/18589934", :vimeo_maps => nil) + }.should_not raise_error + end + describe "autolinks" do it "should not allow basic XSS/HTML" do markdownify("").should == "<script>alert('XSS is evil')</script>"