html-pipeline 2.14.0 → 2.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a897e9a165c69f5823336a5ca9cf92205c191ad6f90ae0d283be3234a9fefcc4
4
- data.tar.gz: a0fb7f552a185bc2ffeb4aba3c8c50a5659b0277763ec0dcbbf28b6f4ce3bfc6
3
+ metadata.gz: 31dccde8e42137b77ce845059270d4a9e67dd5d9583041574c64accb8828559a
4
+ data.tar.gz: 1e47ca071dfa2d7f2c1126e55cab52278f25772613a4ce4b3f67c98344ef731e
5
5
  SHA512:
6
- metadata.gz: c90bcf04d6113d1c9d7a33a4f0dc235dc9d4e302fa1683e36e4c34e96777a307bd5b76b23bad07a02b6bdea8e5577e90e90a57f346e579bbcc6d287f4023623d
7
- data.tar.gz: 2ea63f52f5365e66d9742d12d28c248794ad7289bd8e68e7b963e42041c1c7ef30be936cd364ed79cb66c43da73c45e9905b90148cae41ecaab5156aa797b0f6
6
+ metadata.gz: 79e9a69864c3b4bf43d2cedf04fda1d43b9f163ea8d32583a88951f4c5d38215146b61ed6b6d92d01594f143f0b36284b9dd96df99bbe8697f2f13bfc0574fc8
7
+ data.tar.gz: 25588dfaec753952ba7ccd77cf50e61bd09eec67e3fc4ccfdd5a50bfd142db9f0e1980c9061947843af308852295321303a0f182e3c55cb692f1bd100d8e3adc
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.
@@ -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
@@ -38,7 +38,7 @@ module HTML
38
38
 
39
39
  render_options = [:GITHUB_PRE_LANG]
40
40
  render_options << :HARDBREAKS if context[:gfm] != false
41
- render_options = [:UNSAFE] if context[:unsafe]
41
+ render_options << :UNSAFE if context[:unsafe]
42
42
 
43
43
  doc = CommonMarker.render_doc(@text, parse_options, extensions)
44
44
  renderer.new(options: render_options, extensions: extensions).render(doc)
@@ -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.14.0'
5
+ VERSION = '2.14.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.14.0
4
+ version: 2.14.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-08-11 00:00:00.000000000 Z
13
+ date: 2022-03-31 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -107,8 +107,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  - !ruby/object:Gem::Version
108
108
  version: '0'
109
109
  requirements: []
110
- rubygems_version: 3.1.2
111
- signing_key:
110
+ rubygems_version: 3.3.3
111
+ signing_key:
112
112
  specification_version: 4
113
113
  summary: Helpers for processing content through a chain of filters
114
114
  test_files: []