html-pipeline 2.13.0 → 2.13.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e8d5622a3fa6bf3a03909aa620ddb19ff0c2b1b3296a2a019410e1f69a5e4fa1
4
- data.tar.gz: f21358c32997b668bd7c8d70756b18763e049ae1a10bbd65bd87d1a84d723efb
3
+ metadata.gz: 98e2f770a5c65764d3f1876186ada3b9f3566997ec706c11a835216b9a5f2cb6
4
+ data.tar.gz: 7a839e8ec04a801868674916f2521d3d098dbace80e57b4f3ce3bc9997592b7b
5
5
  SHA512:
6
- metadata.gz: e2d55abf9182888317ecdc9e426185ecea7d4047096766082d9f271df78b21fb257bfacbcecf9ca500aac8bc1e7db5a00dbdc9b762bb2cae18205c55228e1215
7
- data.tar.gz: cc8eedcfeb8cebfbd651f0f1ba86391857e825766e1a87d9b4c330f42bdbb881dda9b6690aed17e7134e49c6bd61ff3ff70e7fac08dd03adead8a1ddb90d710c
6
+ metadata.gz: 63e9bd15cf65b8765d1046d77f7a675d3dc44d8c82a717bec18722b38275753010c9793f3dec3fcf46f7ad5e4021e33b96280efa6324a3cb37092606c5c37f50
7
+ data.tar.gz: df99642a2bc048ce6d5f7e52dc1816c5589af7a7503b7f69f842fbc361d70e57601376b437cd56b40161d131d27eddc31b62230f6d7672ccfba3666afef6e1df
data/README.md CHANGED
@@ -33,7 +33,7 @@ And then execute:
33
33
  $ bundle
34
34
  ```
35
35
 
36
- Or install it yourself as:
36
+ Or install it by yourself as:
37
37
 
38
38
  ```sh
39
39
  $ gem install html-pipeline
@@ -164,7 +164,7 @@ EmojiPipeline = Pipeline.new [
164
164
  * `ImageMaxWidthFilter` - link to full size image for large images
165
165
  * `MarkdownFilter` - convert markdown to html
166
166
  * `PlainTextInputFilter` - html escape text and wrap the result in a div
167
- * `SanitizationFilter` - whitelist sanitize user markup
167
+ * `SanitizationFilter` - allow sanitize user markup
168
168
  * `SyntaxHighlightFilter` - code syntax highlighter
169
169
  * `TextileFilter` - convert textile to html
170
170
  * `TableOfContentsFilter` - anchor headings with name attributes and generate Table of Contents html unordered list linking headings
@@ -330,9 +330,9 @@ html_fragment = "This is outside of an html element, but <strong>this isn't. :+1
330
330
  EmojiPipeline.call("<div>#{html_fragment}</div>") # <- Wrap your own html fragments to avoid escaping
331
331
  ```
332
332
 
333
- ### 2. How do I customize a whitelist for `SanitizationFilter`s?
333
+ ### 2. How do I customize an allowlist for `SanitizationFilter`s?
334
334
 
335
- `SanitizationFilter::WHITELIST` is the default whitelist used if no `:whitelist`
335
+ `SanitizationFilter::ALLOWLIST` is the default allowlist used if no `:allowlist`
336
336
  argument is given in the context. The default is a good starting template for
337
337
  you to add additional elements. You can either modify the constant's value, or
338
338
  re-define your own constant and pass that in via the context.
@@ -8,6 +8,7 @@ module HTML
8
8
  #
9
9
  # Context options:
10
10
  # :autolink - boolean whether to autolink urls
11
+ # :link_mode - :all, :urls or :email_addresses
11
12
  # :link_attr - HTML attributes for the link that will be generated
12
13
  # :skip_tags - HTML tags inside which autolinking will be skipped.
13
14
  # See Rinku.skip_tags
@@ -22,7 +23,11 @@ module HTML
22
23
  flags = 0
23
24
  flags |= context[:flags] if context[:flags]
24
25
 
25
- Rinku.auto_link(html, :urls, context[:link_attr], skip_tags, flags)
26
+ Rinku.auto_link(html, link_mode, context[:link_attr], skip_tags, flags)
27
+ end
28
+
29
+ def link_mode
30
+ context[:link_mode] || :urls
26
31
  end
27
32
  end
28
33
  end
@@ -16,7 +16,7 @@ module HTML
16
16
  # Context options:
17
17
  # :asset_proxy (required) - Base URL for constructed asset proxy URLs.
18
18
  # :asset_proxy_secret_key (required) - The shared secret used to encode URLs.
19
- # :asset_proxy_whitelist - Array of host Strings or Regexps to skip
19
+ # :asset_proxy_allowlist - Array of host Strings or Regexps to skip
20
20
  # src rewriting.
21
21
  #
22
22
  # This filter does not write additional information to the context.
@@ -37,7 +37,7 @@ module HTML
37
37
  end
38
38
 
39
39
  next if uri.host.nil?
40
- next if asset_host_whitelisted?(uri.host)
40
+ next if asset_host_allowed?(uri.host)
41
41
 
42
42
  element['src'] = asset_proxy_url(original_src)
43
43
  element['data-canonical-src'] = original_src
@@ -76,11 +76,21 @@ module HTML
76
76
  end
77
77
 
78
78
  def asset_proxy_whitelist
79
- context[:asset_proxy_whitelist] || []
79
+ warn "[DEPRECATION] 'asset_proxy_whitelist' is deprecated. Please use 'asset_proxy_allowlist' instead."
80
+ asset_proxy_allowlist
81
+ end
82
+
83
+ def asset_proxy_allowlist
84
+ context[:asset_proxy_allowlist] || context[:asset_proxy_whitelist] || []
80
85
  end
81
86
 
82
87
  def asset_host_whitelisted?(host)
83
- asset_proxy_whitelist.any? do |test|
88
+ warn "[DEPRECATION] 'asset_host_whitelisted?' is deprecated. Please use 'asset_host_allowed?' instead."
89
+ asset_host_allowed?(host)
90
+ end
91
+
92
+ def asset_host_allowed?(host)
93
+ asset_proxy_allowlist.any? do |test|
84
94
  test.is_a?(String) ? host == test : test.match(host)
85
95
  end
86
96
  end
@@ -4,7 +4,7 @@ HTML::Pipeline.require_dependency('sanitize', 'SanitizationFilter')
4
4
 
5
5
  module HTML
6
6
  class Pipeline
7
- # HTML filter with sanization routines and whitelists. This module defines
7
+ # HTML filter with sanization routines and allowlists. This module defines
8
8
  # what HTML is allowed in user provided content and fixes up issues with
9
9
  # unbalanced tags and whatnot.
10
10
  #
@@ -13,13 +13,13 @@ module HTML
13
13
  # https://github.com/rgrove/sanitize/#readme
14
14
  #
15
15
  # Context options:
16
- # :whitelist - The sanitizer whitelist configuration to use. This
16
+ # :allowlist - The sanitizer allowlist configuration to use. This
17
17
  # can be one of the options constants defined in this
18
18
  # class or a custom sanitize options hash.
19
19
  # :anchor_schemes - The URL schemes to allow in <a href> attributes. The
20
20
  # default set is provided in the ANCHOR_SCHEMES
21
21
  # constant in this class. If passed, this overrides any
22
- # schemes specified in the whitelist configuration.
22
+ # schemes specified in the allowlist configuration.
23
23
  #
24
24
  # This filter does not write additional information to the context.
25
25
  class SanitizationFilter < Filter
@@ -37,9 +37,9 @@ module HTML
37
37
  # These schemes are the only ones allowed in <a href> attributes by default.
38
38
  ANCHOR_SCHEMES = ['http', 'https', 'mailto', 'xmpp', :relative, 'github-windows', 'github-mac', 'irc', 'ircs'].freeze
39
39
 
40
- # The main sanitization whitelist. Only these elements and attributes are
40
+ # The main sanitization allowlist. Only these elements and attributes are
41
41
  # allowed through by default.
42
- WHITELIST = {
42
+ ALLOWLIST = {
43
43
  elements: %w[
44
44
  h1 h2 h3 h4 h5 h6 h7 h8 br b i strong em a pre code img tt
45
45
  div ins del sup sub p ol ul table thead tbody tfoot blockquote
@@ -68,7 +68,7 @@ module HTML
68
68
  hspace ismap label lang
69
69
  maxlength media method
70
70
  multiple name nohref noshade
71
- nowrap open prompt readonly rel rev
71
+ nowrap open progress prompt readonly rel rev
72
72
  role rows rowspan rules scope
73
73
  selected shape size span
74
74
  start summary tabindex target
@@ -108,10 +108,10 @@ module HTML
108
108
  ].freeze
109
109
  }.freeze
110
110
 
111
- # A more limited sanitization whitelist. This includes all attributes,
112
- # protocols, and transformers from WHITELIST but with a more locked down
111
+ # A more limited sanitization allowlist. This includes all attributes,
112
+ # protocols, and transformers from ALLOWLIST but with a more locked down
113
113
  # set of allowed elements.
114
- LIMITED = WHITELIST.merge(
114
+ LIMITED = ALLOWLIST.merge(
115
115
  elements: %w[b i strong em a pre code img ins del sup sub mark abbr p ol ul li]
116
116
  )
117
117
 
@@ -120,19 +120,24 @@ module HTML
120
120
 
121
121
  # Sanitize markup using the Sanitize library.
122
122
  def call
123
- Sanitize.clean_node!(doc, whitelist)
123
+ Sanitize.clean_node!(doc, allowlist)
124
124
  end
125
125
 
126
- # The whitelist to use when sanitizing. This can be passed in the context
127
- # hash to the filter but defaults to WHITELIST constant value above.
128
126
  def whitelist
129
- whitelist = context[:whitelist] || WHITELIST
127
+ warn "[DEPRECATION] 'whitelist' is deprecated. Please use 'allowlist' instead."
128
+ allowlist
129
+ end
130
+
131
+ # The allowlist to use when sanitizing. This can be passed in the context
132
+ # hash to the filter but defaults to ALLOWLIST constant value above.
133
+ def allowlist
134
+ allowlist = context[:allowlist] || context[:whitelist] || ALLOWLIST
130
135
  anchor_schemes = context[:anchor_schemes]
131
- return whitelist unless anchor_schemes
132
- whitelist = whitelist.dup
133
- whitelist[:protocols] = (whitelist[:protocols] || {}).dup
134
- whitelist[:protocols]['a'] = (whitelist[:protocols]['a'] || {}).merge('href' => anchor_schemes)
135
- whitelist
136
+ return allowlist unless anchor_schemes
137
+ allowlist = allowlist.dup
138
+ allowlist[:protocols] = (allowlist[:protocols] || {}).dup
139
+ allowlist[:protocols]['a'] = (allowlist[:protocols]['a'] || {}).merge('href' => anchor_schemes)
140
+ allowlist
136
141
  end
137
142
  end
138
143
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module HTML
4
4
  class Pipeline
5
- VERSION = '2.13.0'
5
+ VERSION = '2.13.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html-pipeline
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.13.0
4
+ version: 2.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Tomayko
8
8
  - Jerry Cheung
9
9
  - Garen J. Torikian
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-05-28 00:00:00.000000000 Z
13
+ date: 2020-12-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  version: '0'
109
109
  requirements: []
110
110
  rubygems_version: 3.1.2
111
- signing_key:
111
+ signing_key:
112
112
  specification_version: 4
113
113
  summary: Helpers for processing content through a chain of filters
114
114
  test_files: []