forked from id774/automaticruby
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from id774/master
Add Filter::Sanitize
- Loading branch information
Showing
6 changed files
with
224 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# -*- coding: utf-8 -*- | ||
# Name:: Automatic::Plugin::Filter::Sanitize | ||
# Author:: 774 <http://id774.net> | ||
# Created:: Jun 20, 2013 | ||
# Updated:: Jun 20, 2013 | ||
# Copyright:: 774 Copyright (c) 2013 | ||
# License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0. | ||
|
||
module Automatic::Plugin | ||
class FilterSanitize | ||
require 'sanitize' | ||
|
||
def initialize(config, pipeline=[]) | ||
@config = config | ||
@pipeline = pipeline | ||
case @config['mode'] | ||
when "basic" | ||
@mode = Sanitize::Config::BASIC | ||
when "relaxed" | ||
@mode = Sanitize::Config::RELAXED | ||
else | ||
@mode = Sanitize::Config::RESTRICTED | ||
end | ||
end | ||
|
||
def run | ||
@return_feeds = [] | ||
@pipeline.each {|feeds| | ||
return_feed_items = [] | ||
unless feeds.nil? | ||
feeds.items.each {|feed| | ||
feed.description = Sanitize.clean(feed.description, @mode) unless feed.description.nil? | ||
} | ||
@return_feeds << feeds | ||
end | ||
} | ||
@return_feeds | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
# -*- coding: utf-8 -*- | ||
# Name:: Automatic::Plugin::Filter::Sanitize | ||
# Author:: 774 <http://id774.net> | ||
# Created:: Jun 20, 2013 | ||
# Updated:: Jun 20, 2013 | ||
# Copyright:: 774 Copyright (c) 2013 | ||
# License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0. | ||
|
||
require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper') | ||
|
||
require 'filter/sanitize' | ||
|
||
describe Automatic::Plugin::FilterSanitize do | ||
context "It should be sanitized" do | ||
subject { | ||
Automatic::Plugin::FilterSanitize.new( | ||
{}, | ||
AutomaticSpec.generate_pipeline { | ||
feed { | ||
item "http://testsite.org", "hoge", | ||
"<a>fuga</a>", | ||
"Mon, 07 Mar 2011 15:54:11 +0900" | ||
} | ||
} | ||
) | ||
} | ||
|
||
describe "#run" do | ||
its(:run) { should have(1).feeds } | ||
|
||
specify { | ||
subject.run | ||
subject.instance_variable_get(:@return_feeds)[0].items. | ||
count.should == 1 | ||
subject.instance_variable_get(:@return_feeds)[0].items[0].description. | ||
should == 'fuga' | ||
} | ||
end | ||
end | ||
|
||
context "It should not be sanitized in basic mode" do | ||
subject { | ||
Automatic::Plugin::FilterSanitize.new( | ||
{ | ||
'mode' => "basic" | ||
}, | ||
AutomaticSpec.generate_pipeline { | ||
feed { | ||
item "http://testsite.org", "hoge", | ||
"<a>fuga</a>", | ||
"Mon, 07 Mar 2011 15:54:11 +0900" | ||
} | ||
} | ||
) | ||
} | ||
|
||
describe "#run" do | ||
its(:run) { should have(1).feeds } | ||
|
||
specify { | ||
subject.run | ||
subject.instance_variable_get(:@return_feeds)[0].items. | ||
count.should == 1 | ||
subject.instance_variable_get(:@return_feeds)[0].items[0].description. | ||
should == '<a rel="nofollow">fuga</a>' | ||
} | ||
end | ||
end | ||
|
||
context "It should not be sanitized in restricted mode" do | ||
subject { | ||
Automatic::Plugin::FilterSanitize.new( | ||
{ | ||
'mode' => "restricted" | ||
}, | ||
AutomaticSpec.generate_pipeline { | ||
feed { | ||
item "http://testsite.org", "hoge", | ||
"<a>fuga</a>", | ||
"Mon, 07 Mar 2011 15:54:11 +0900" | ||
} | ||
} | ||
) | ||
} | ||
|
||
describe "#run" do | ||
its(:run) { should have(1).feeds } | ||
|
||
specify { | ||
subject.run | ||
subject.instance_variable_get(:@return_feeds)[0].items. | ||
count.should == 1 | ||
subject.instance_variable_get(:@return_feeds)[0].items[0].description. | ||
should == 'fuga' | ||
} | ||
end | ||
end | ||
|
||
context "It should not be sanitized in relaxed mode" do | ||
subject { | ||
Automatic::Plugin::FilterSanitize.new( | ||
{ | ||
'mode' => "relaxed" | ||
}, | ||
AutomaticSpec.generate_pipeline { | ||
feed { | ||
item "http://testsite.org", "hoge", | ||
"<a>fuga</a>", | ||
"Mon, 07 Mar 2011 15:54:11 +0900" | ||
} | ||
} | ||
) | ||
} | ||
|
||
describe "#run" do | ||
its(:run) { should have(1).feeds } | ||
|
||
specify { | ||
subject.run | ||
subject.instance_variable_get(:@return_feeds)[0].items. | ||
count.should == 1 | ||
subject.instance_variable_get(:@return_feeds)[0].items[0].description. | ||
should == '<a>fuga</a>' | ||
} | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
global: | ||
timezone: Asia/Tokyo | ||
cache: | ||
base: /tmp | ||
log: | ||
level: info | ||
|
||
plugins: | ||
- module: SubscriptionFeed | ||
config: | ||
feeds: | ||
- http://blog.id774.net/post/feed/ | ||
|
||
- module: FilterSanitize | ||
config: | ||
mode: restricted | ||
|
||
- module: StoreFullText | ||
config: | ||
db: test_sanitize.db | ||
|
||
# - module: PublishConsole |