antisamy 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/CHANGELOG.rdoc +13 -0
  2. data/LICENSE.txt +20 -20
  3. data/README.rdoc +41 -41
  4. data/lib/antisamy.rb +46 -46
  5. data/lib/antisamy/css/css_filter.rb +187 -187
  6. data/lib/antisamy/css/css_scanner.rb +84 -84
  7. data/lib/antisamy/css/css_validator.rb +128 -128
  8. data/lib/antisamy/csspool/rsac.rb +1 -1
  9. data/lib/antisamy/csspool/rsac/sac.rb +14 -14
  10. data/lib/antisamy/csspool/rsac/sac/conditions.rb +5 -5
  11. data/lib/antisamy/csspool/rsac/sac/conditions/attribute_condition.rb +50 -50
  12. data/lib/antisamy/csspool/rsac/sac/conditions/begin_hyphen_condition.rb +18 -18
  13. data/lib/antisamy/csspool/rsac/sac/conditions/class_condition.rb +18 -18
  14. data/lib/antisamy/csspool/rsac/sac/conditions/combinator_condition.rb +36 -36
  15. data/lib/antisamy/csspool/rsac/sac/conditions/condition.rb +29 -29
  16. data/lib/antisamy/csspool/rsac/sac/conditions/id_condition.rb +23 -23
  17. data/lib/antisamy/csspool/rsac/sac/conditions/one_of_condition.rb +18 -18
  18. data/lib/antisamy/csspool/rsac/sac/conditions/pseudo_class_condition.rb +20 -20
  19. data/lib/antisamy/csspool/rsac/sac/document_handler.rb +66 -66
  20. data/lib/antisamy/csspool/rsac/sac/error_handler.rb +13 -13
  21. data/lib/antisamy/csspool/rsac/sac/generated_parser.rb +1012 -1012
  22. data/lib/antisamy/csspool/rsac/sac/generated_property_parser.rb +9284 -9284
  23. data/lib/antisamy/csspool/rsac/sac/lexeme.rb +27 -27
  24. data/lib/antisamy/csspool/rsac/sac/lexical_unit.rb +201 -201
  25. data/lib/antisamy/csspool/rsac/sac/parse_exception.rb +4 -4
  26. data/lib/antisamy/csspool/rsac/sac/parser.rb +109 -109
  27. data/lib/antisamy/csspool/rsac/sac/property_parser.rb +44 -44
  28. data/lib/antisamy/csspool/rsac/sac/selectors.rb +5 -5
  29. data/lib/antisamy/csspool/rsac/sac/selectors/child_selector.rb +36 -36
  30. data/lib/antisamy/csspool/rsac/sac/selectors/conditional_selector.rb +45 -45
  31. data/lib/antisamy/csspool/rsac/sac/selectors/descendant_selector.rb +36 -36
  32. data/lib/antisamy/csspool/rsac/sac/selectors/element_selector.rb +35 -35
  33. data/lib/antisamy/csspool/rsac/sac/selectors/selector.rb +25 -25
  34. data/lib/antisamy/csspool/rsac/sac/selectors/sibling_selector.rb +35 -35
  35. data/lib/antisamy/csspool/rsac/sac/selectors/simple_selector.rb +21 -21
  36. data/lib/antisamy/csspool/rsac/sac/token.rb +25 -25
  37. data/lib/antisamy/csspool/rsac/sac/tokenizer.rb +185 -185
  38. data/lib/antisamy/csspool/rsac/stylesheet.rb +3 -3
  39. data/lib/antisamy/csspool/rsac/stylesheet/rule.rb +20 -20
  40. data/lib/antisamy/csspool/rsac/stylesheet/stylesheet.rb +76 -76
  41. data/lib/antisamy/html/handler.rb +112 -99
  42. data/lib/antisamy/html/sax_filter.rb +305 -302
  43. data/lib/antisamy/html/scanner.rb +47 -43
  44. data/lib/antisamy/model/attribute.rb +19 -19
  45. data/lib/antisamy/model/css_property.rb +39 -39
  46. data/lib/antisamy/model/tag.rb +31 -31
  47. data/lib/antisamy/policy.rb +577 -545
  48. data/lib/antisamy/scan_results.rb +89 -89
  49. data/spec/antisamy_spec.rb +208 -142
  50. data/spec/spec_helper.rb +12 -12
  51. metadata +79 -81
@@ -1,5 +1,5 @@
1
- require "antisamy/csspool/rsac/sac/conditions/condition"
2
-
3
- %w(attribute begin_hyphen class combinator id one_of pseudo_class).each do |type|
4
- require "antisamy/csspool/rsac/sac/conditions/#{type}_condition"
5
- end
1
+ require "antisamy/csspool/rsac/sac/conditions/condition"
2
+
3
+ %w(attribute begin_hyphen class combinator id one_of pseudo_class).each do |type|
4
+ require "antisamy/csspool/rsac/sac/conditions/#{type}_condition"
5
+ end
@@ -1,50 +1,50 @@
1
- module RSAC
2
- module Conditions
3
- class AttributeCondition < Condition
4
- attr_accessor :local_name, :value, :specified
5
- alias :specified? :specified
6
-
7
- class << self
8
- def build(name, raw)
9
- condition, value = raw
10
- case condition
11
- when "~="
12
- OneOfCondition.new(name, value)
13
- when "|="
14
- BeginHyphenCondition.new(name, value)
15
- else
16
- AttributeCondition.new(name, value, true)
17
- end
18
- end
19
- end
20
-
21
- def initialize(local_name, value, specified, condition_type=:SAC_ATTRIBUTE_CONDITION)
22
- super(condition_type)
23
- @local_name = local_name
24
- @value = value
25
- @specified = specified
26
- end
27
-
28
- def to_css
29
- "[#{local_name}#{value && "=#{value}"}]"
30
- end
31
-
32
- def to_xpath
33
- "[@#{local_name}#{value && "='#{value}'"}]"
34
- end
35
-
36
- def specificity
37
- [0, 0, 1, 0]
38
- end
39
-
40
- def ==(other)
41
- super && local_name == other.local_name && value == other.value &&
42
- specified == other.specified
43
- end
44
-
45
- def hash
46
- [local_name, value, specified].hash
47
- end
48
- end
49
- end
50
- end
1
+ module RSAC
2
+ module Conditions
3
+ class AttributeCondition < Condition
4
+ attr_accessor :local_name, :value, :specified
5
+ alias :specified? :specified
6
+
7
+ class << self
8
+ def build(name, raw)
9
+ condition, value = raw
10
+ case condition
11
+ when "~="
12
+ OneOfCondition.new(name, value)
13
+ when "|="
14
+ BeginHyphenCondition.new(name, value)
15
+ else
16
+ AttributeCondition.new(name, value, true)
17
+ end
18
+ end
19
+ end
20
+
21
+ def initialize(local_name, value, specified, condition_type=:SAC_ATTRIBUTE_CONDITION)
22
+ super(condition_type)
23
+ @local_name = local_name
24
+ @value = value
25
+ @specified = specified
26
+ end
27
+
28
+ def to_css
29
+ "[#{local_name}#{value && "=#{value}"}]"
30
+ end
31
+
32
+ def to_xpath
33
+ "[@#{local_name}#{value && "='#{value}'"}]"
34
+ end
35
+
36
+ def specificity
37
+ [0, 0, 1, 0]
38
+ end
39
+
40
+ def ==(other)
41
+ super && local_name == other.local_name && value == other.value &&
42
+ specified == other.specified
43
+ end
44
+
45
+ def hash
46
+ [local_name, value, specified].hash
47
+ end
48
+ end
49
+ end
50
+ end
@@ -1,18 +1,18 @@
1
- module RSAC
2
- module Conditions
3
- class BeginHyphenCondition < AttributeCondition
4
-
5
- def initialize(local_name, value)
6
- super(local_name, value, true, :SAC_BEGIN_HYPHEN_ATTRIBUTE_CONDITION)
7
- end
8
-
9
- def to_css
10
- "[#{local_name}|=#{value}]"
11
- end
12
-
13
- def to_xpath
14
- "[contains(@#{local_name}, '#{value}')]"
15
- end
16
- end
17
- end
18
- end
1
+ module RSAC
2
+ module Conditions
3
+ class BeginHyphenCondition < AttributeCondition
4
+
5
+ def initialize(local_name, value)
6
+ super(local_name, value, true, :SAC_BEGIN_HYPHEN_ATTRIBUTE_CONDITION)
7
+ end
8
+
9
+ def to_css
10
+ "[#{local_name}|=#{value}]"
11
+ end
12
+
13
+ def to_xpath
14
+ "[contains(@#{local_name}, '#{value}')]"
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,18 +1,18 @@
1
- module RSAC
2
- module Conditions
3
- class ClassCondition < AttributeCondition
4
-
5
- def initialize(klass)
6
- super("class", klass, true, :SAC_CLASS_CONDITION)
7
- end
8
-
9
- def to_css
10
- ".#{value}"
11
- end
12
-
13
- def to_xpath
14
- "[contains(@#{local_name}, '#{value}')]"
15
- end
16
- end
17
- end
18
- end
1
+ module RSAC
2
+ module Conditions
3
+ class ClassCondition < AttributeCondition
4
+
5
+ def initialize(klass)
6
+ super("class", klass, true, :SAC_CLASS_CONDITION)
7
+ end
8
+
9
+ def to_css
10
+ ".#{value}"
11
+ end
12
+
13
+ def to_xpath
14
+ "[contains(@#{local_name}, '#{value}')]"
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,36 +1,36 @@
1
- module RSAC
2
- module Conditions
3
- class CombinatorCondition < Condition
4
- attr_accessor :first_condition, :second_condition
5
- alias :first :first_condition
6
- alias :second :second_condition
7
-
8
- def initialize(first, second)
9
- super(:SAC_AND_CONDITION)
10
-
11
- @first_condition = first
12
- @second_condition = second
13
- end
14
-
15
- def to_css
16
- "#{first.to_css}#{second.to_css}"
17
- end
18
-
19
- def to_xpath
20
- "#{first.to_xpath}#{second.to_xpath}"
21
- end
22
-
23
- def specificity
24
- first.specificity.zip(second.specificity).map { |x,y| x + y }
25
- end
26
-
27
- def ==(other)
28
- super && first == other.first && second == other.second
29
- end
30
-
31
- def hash
32
- [first, second].hash
33
- end
34
- end
35
- end
36
- end
1
+ module RSAC
2
+ module Conditions
3
+ class CombinatorCondition < Condition
4
+ attr_accessor :first_condition, :second_condition
5
+ alias :first :first_condition
6
+ alias :second :second_condition
7
+
8
+ def initialize(first, second)
9
+ super(:SAC_AND_CONDITION)
10
+
11
+ @first_condition = first
12
+ @second_condition = second
13
+ end
14
+
15
+ def to_css
16
+ "#{first.to_css}#{second.to_css}"
17
+ end
18
+
19
+ def to_xpath
20
+ "#{first.to_xpath}#{second.to_xpath}"
21
+ end
22
+
23
+ def specificity
24
+ first.specificity.zip(second.specificity).map { |x,y| x + y }
25
+ end
26
+
27
+ def ==(other)
28
+ super && first == other.first && second == other.second
29
+ end
30
+
31
+ def hash
32
+ [first, second].hash
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,29 +1,29 @@
1
- module RSAC
2
- module Conditions
3
- class Condition
4
-
5
- attr_accessor :condition_type
6
-
7
- def initialize(condition_type)
8
- @condition_type = condition_type
9
- end
10
-
11
- def ==(other)
12
- self.class === other && condition_type == other.condition_type
13
- end
14
-
15
- def hash
16
- condition_type.hash
17
- end
18
-
19
- def eql?(other)
20
- self == other
21
- end
22
-
23
- def to_css
24
- nil
25
- end
26
-
27
- end
28
- end
29
- end
1
+ module RSAC
2
+ module Conditions
3
+ class Condition
4
+
5
+ attr_accessor :condition_type
6
+
7
+ def initialize(condition_type)
8
+ @condition_type = condition_type
9
+ end
10
+
11
+ def ==(other)
12
+ self.class === other && condition_type == other.condition_type
13
+ end
14
+
15
+ def hash
16
+ condition_type.hash
17
+ end
18
+
19
+ def eql?(other)
20
+ self == other
21
+ end
22
+
23
+ def to_css
24
+ nil
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -1,23 +1,23 @@
1
- module RSAC
2
- module Conditions
3
- class IDCondition < AttributeCondition
4
-
5
- def initialize(id)
6
- id = id[1..id.size] if id[0] == ?#
7
- super("id", id, true, :SAC_ID_CONDITION)
8
- end
9
-
10
- def to_css
11
- "##{value}"
12
- end
13
-
14
- def to_xpath
15
- "[@id='#{value}']"
16
- end
17
-
18
- def specificity
19
- [0, 1, 0, 0]
20
- end
21
- end
22
- end
23
- end
1
+ module RSAC
2
+ module Conditions
3
+ class IDCondition < AttributeCondition
4
+
5
+ def initialize(id)
6
+ id = id[1..id.size] if id[0] == ?#
7
+ super("id", id, true, :SAC_ID_CONDITION)
8
+ end
9
+
10
+ def to_css
11
+ "##{value}"
12
+ end
13
+
14
+ def to_xpath
15
+ "[@id='#{value}']"
16
+ end
17
+
18
+ def specificity
19
+ [0, 1, 0, 0]
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,18 +1,18 @@
1
- module RSAC
2
- module Conditions
3
- class OneOfCondition < AttributeCondition
4
-
5
- def initialize(local_name, value)
6
- super(local_name, value, true, :SAC_ONE_OF_ATTRIBUTE_CONDITION)
7
- end
8
-
9
- def to_css
10
- "[#{local_name}~=#{value}]"
11
- end
12
-
13
- def to_xpath
14
- "[contains(@#{local_name}, '#{value}')]"
15
- end
16
- end
17
- end
18
- end
1
+ module RSAC
2
+ module Conditions
3
+ class OneOfCondition < AttributeCondition
4
+
5
+ def initialize(local_name, value)
6
+ super(local_name, value, true, :SAC_ONE_OF_ATTRIBUTE_CONDITION)
7
+ end
8
+
9
+ def to_css
10
+ "[#{local_name}~=#{value}]"
11
+ end
12
+
13
+ def to_xpath
14
+ "[contains(@#{local_name}, '#{value}')]"
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,20 +1,20 @@
1
- module RSAC
2
- module Conditions
3
- class PseudoClassCondition < AttributeCondition
4
- def initialize(pseudo_class)
5
- super(nil, pseudo_class, false, :SAC_PSEUDO_CLASS_CONDITION)
6
- end
7
-
8
- def to_css
9
- ":#{value}"
10
- end
11
-
12
- def to_xpath
13
- end
14
-
15
- def specificity
16
- [0, 0, 0, 0]
17
- end
18
- end
19
- end
20
- end
1
+ module RSAC
2
+ module Conditions
3
+ class PseudoClassCondition < AttributeCondition
4
+ def initialize(pseudo_class)
5
+ super(nil, pseudo_class, false, :SAC_PSEUDO_CLASS_CONDITION)
6
+ end
7
+
8
+ def to_css
9
+ ":#{value}"
10
+ end
11
+
12
+ def to_xpath
13
+ end
14
+
15
+ def specificity
16
+ [0, 0, 0, 0]
17
+ end
18
+ end
19
+ end
20
+ end