From 69683467031b3a34c64fc160ff6ea8fd18aa0466 Mon Sep 17 00:00:00 2001 From: Martin Vilcans Date: Sat, 2 May 2009 00:44:33 +0200 Subject: [PATCH] Added cgi_escape filter --- lib/jekyll/filters.rb | 4 ++++ test/test_filters.rb | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/jekyll/filters.rb b/lib/jekyll/filters.rb index 1e369175..442547c3 100644 --- a/lib/jekyll/filters.rb +++ b/lib/jekyll/filters.rb @@ -21,6 +21,10 @@ module Jekyll input.gsub("&", "&").gsub("<", "<").gsub(">", ">") end + def cgi_escape(input) + CGI::escape(input) + end + def number_of_words(input) input.split.length end diff --git a/test/test_filters.rb b/test/test_filters.rb index e0893f03..bb2d8f82 100644 --- a/test/test_filters.rb +++ b/test/test_filters.rb @@ -37,5 +37,13 @@ class TestFilters < Test::Unit::TestCase assert_equal "AT&T", @filter.xml_escape("AT&T") assert_equal "<code>command &lt;filename&gt;</code>", @filter.xml_escape("command <filename>") end + + should "escape space as plus" do + assert_equal "my+things", @filter.cgi_escape("my things") + end + + should "escape special characters" do + assert_equal "hey%21", @filter.cgi_escape("hey!") + end end end