better_html 1.0.11 → 1.0.16

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
- SHA1:
3
- metadata.gz: 5a62a4416eaa383372a21c1b8f90494d681ad7ca
4
- data.tar.gz: bf03706d26596c0b03bec716d2b55f35324221b3
2
+ SHA256:
3
+ metadata.gz: e8dc392542e380b0d3cb63c331cf0524f1b016f15fb99c907e8fd951fb22eae7
4
+ data.tar.gz: 3393a92593172019c1180c9ca3ed8dc81c9c043954b9d0a221dd82dcd399f8dd
5
5
  SHA512:
6
- metadata.gz: 8ede71b45ba3cc636f1d77e76eab6e22eb539014a4fe049e9f91796bb3efc7c8c8d6629f6b2cb8f6a80738a26a892d39341b0c578b28d222a353b945f18266ac
7
- data.tar.gz: 788384054b7e79a080dda17b7cbb3658e14ba1034849ca855fe9e144ac47126246631984ab509c986515e82a063133a647bf94b5f3986b0b3bf8aebb40ffbeaf
6
+ metadata.gz: d47ab514dcb80da8a3392dd933f4f51ccd88aa538c06fa94d325c8146c4f70250c0e57573d86ed726c58127591a9907f19183e5c640218bcadf5b09e724a83ef
7
+ data.tar.gz: e9d3f1534fa3f9dfad8ff0f2290bf09b9b4b221584c28cb5bc3ec67663cbe739d86d281b544d002eb1666c7772e1f0bb9bd7c67026807cf2719af661bf93cc71
@@ -27,27 +27,28 @@ class BetterHtml::BetterErb
27
27
 
28
28
  module ConditionalImplementation
29
29
 
30
- def call(template)
31
- generate(template)
30
+ def call(template, source = nil)
31
+ generate(template, source)
32
32
  end
33
33
 
34
34
  private
35
35
 
36
- def generate(template)
36
+ def generate(template, source)
37
37
  # First, convert to BINARY, so in case the encoding is
38
38
  # wrong, we can still find an encoding tag
39
39
  # (<%# encoding %>) inside the String using a regular
40
40
  # expression
41
41
 
42
+ source ||= template.source
42
43
  filename = template.identifier.split("/").last
43
44
  exts = filename.split(".")
44
45
  exts = exts[1..exts.length].join(".")
45
- template_source = template.source.dup.force_encoding(Encoding::ASCII_8BIT)
46
+ template_source = source.dup.force_encoding(Encoding::ASCII_8BIT)
46
47
 
47
48
  erb = template_source.gsub(ActionView::Template::Handlers::ERB::ENCODING_TAG, '')
48
49
  encoding = $2
49
50
 
50
- erb.force_encoding valid_encoding(template.source.dup, encoding)
51
+ erb.force_encoding valid_encoding(source.dup, encoding)
51
52
 
52
53
  # Always make sure we return a String in the default_internal
53
54
  erb.encode!
@@ -56,9 +57,14 @@ class BetterHtml::BetterErb
56
57
  klass = BetterHtml::BetterErb.content_types[exts] unless excluded_template
57
58
  klass ||= self.class.erb_implementation
58
59
 
60
+ escape = if ActionView::VERSION::MAJOR <= 5
61
+ self.class.escape_whitelist.include?(template.type)
62
+ else
63
+ self.class.escape_ignore_list.include?(template.type)
64
+ end
59
65
  generator = klass.new(
60
66
  erb,
61
- :escape => (self.class.escape_whitelist.include? template.type),
67
+ :escape => escape,
62
68
  :trim => (self.class.erb_trim_mode == "-")
63
69
  )
64
70
  generator.validate! if generator.respond_to?(:validate!)
@@ -4,14 +4,14 @@ module BetterHtml
4
4
  class Config
5
5
  include SmartProperties
6
6
 
7
- property :partial_tag_name_pattern, default: /\A[a-z0-9\-\:]+\z/
8
- property :partial_attribute_name_pattern, default: /\A[a-zA-Z0-9\-\:]+\z/
7
+ property :partial_tag_name_pattern, default: -> { /\A[a-z0-9\-\:]+\z/ }
8
+ property :partial_attribute_name_pattern, default: -> { /\A[a-zA-Z0-9\-\:]+\z/ }
9
9
  property :allow_single_quoted_attributes, default: true
10
10
  property :allow_unquoted_attributes, default: false
11
- property :javascript_safe_methods, default: ['to_json']
12
- property :javascript_attribute_names, default: [/\Aon/i]
11
+ property :javascript_safe_methods, default: -> { ['to_json'] }
12
+ property :javascript_attribute_names, default: -> { [/\Aon/i] }
13
13
  property :template_exclusion_filter
14
- property :lodash_safe_javascript_expression, default: [/\AJSON\.stringify\(/]
14
+ property :lodash_safe_javascript_expression, default: -> { [/\AJSON\.stringify\(/] }
15
15
 
16
16
  def javascript_attribute_name?(name)
17
17
  javascript_attribute_names.any?{ |other| other === name.to_s }
@@ -1,3 +1,4 @@
1
+ require 'better_html/parser'
1
2
  require 'parser/current'
2
3
 
3
4
  module BetterHtml
@@ -39,7 +39,7 @@ EOF
39
39
  options[:template_language] ||= :html
40
40
  buffer = ::Parser::Source::Buffer.new(options[:filename] || '(buffer)')
41
41
  buffer.source = data
42
- parser = BetterHtml::Parser.new(buffer, options)
42
+ parser = BetterHtml::Parser.new(buffer, **options)
43
43
 
44
44
  tester_classes = [
45
45
  SafeErb::NoStatements,
@@ -52,7 +52,7 @@ EOF
52
52
  end
53
53
 
54
54
  testers = tester_classes.map do |tester_klass|
55
- tester = tester_klass.new(parser)
55
+ tester_klass.new(parser)
56
56
  end
57
57
  testers.each(&:validate)
58
58
  errors = testers.map(&:errors).flatten
@@ -1,6 +1,7 @@
1
1
  require 'better_html/test_helper/safety_error'
2
2
  require 'better_html/ast/iterator'
3
3
  require 'better_html/tree/tag'
4
+ require 'better_html/parser'
4
5
 
5
6
  module BetterHtml
6
7
  module TestHelper
@@ -49,20 +49,20 @@ module BetterHtml
49
49
  def add_erb_tokens(ltrim, indicator, code, rtrim)
50
50
  pos = current_position
51
51
 
52
- token = add_token(:erb_begin, pos, pos + 2)
52
+ add_token(:erb_begin, pos, pos + 2)
53
53
  pos += 2
54
54
 
55
55
  if ltrim
56
- token = add_token(:trim, pos, pos + ltrim.length)
56
+ add_token(:trim, pos, pos + ltrim.length)
57
57
  pos += ltrim.length
58
58
  end
59
59
 
60
60
  if indicator
61
- token = add_token(:indicator, pos, pos + indicator.length)
61
+ add_token(:indicator, pos, pos + indicator.length)
62
62
  pos += indicator.length
63
63
  end
64
64
 
65
- token = add_token(:code, pos, pos + code.length)
65
+ add_token(:code, pos, pos + code.length)
66
66
  pos += code.length
67
67
 
68
68
  if rtrim
@@ -70,7 +70,7 @@ module BetterHtml
70
70
  pos += rtrim.length
71
71
  end
72
72
 
73
- token = add_token(:erb_end, pos, pos + 2)
73
+ add_token(:erb_end, pos, pos + 2)
74
74
  end
75
75
 
76
76
  def add_token(type, begin_pos, end_pos)
@@ -1,4 +1,5 @@
1
1
  require 'active_support'
2
+ require 'html_tokenizer'
2
3
  require_relative 'token'
3
4
  require_relative 'location'
4
5
 
@@ -1,3 +1,3 @@
1
1
  module BetterHtml
2
- VERSION = "1.0.11"
2
+ VERSION = "1.0.16"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require 'test_helper'
2
+ require 'better_html/parser'
2
3
  require 'better_html/test_helper/safe_erb/allowed_script_type'
3
4
 
4
5
  module BetterHtml
@@ -1,4 +1,5 @@
1
1
  require 'test_helper'
2
+ require 'better_html/parser'
2
3
  require 'better_html/test_helper/safe_erb/no_statements'
3
4
 
4
5
  module BetterHtml
@@ -1,4 +1,5 @@
1
1
  require 'test_helper'
2
+ require 'active_support/core_ext/array/access'
2
3
  require 'better_html/tokenizer/token'
3
4
  require 'better_html/tokenizer/location'
4
5
  require 'better_html/tokenizer/token_array'
@@ -1,7 +1,6 @@
1
1
  require "active_support"
2
2
  require "minitest/autorun"
3
3
  require 'better_html'
4
- require 'better_html/parser'
5
4
 
6
5
  # Filter out Minitest backtrace while allowing backtrace from other libraries
7
6
  # to be shown.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: better_html
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.11
4
+ version: 1.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francois Chagnon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-24 00:00:00.000000000 Z
11
+ date: 2021-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ast
@@ -222,7 +222,11 @@ files:
222
222
  homepage: https://github.com/Shopify/better-html
223
223
  licenses:
224
224
  - MIT
225
- metadata: {}
225
+ metadata:
226
+ bug_tracker_uri: https://github.com/Shopify/better-html/issues
227
+ changelog_uri: https://github.com/Shopify/better-html/releases
228
+ source_code_uri: https://github.com/Shopify/better-html/tree/v1.0.16
229
+ allowed_push_host: https://rubygems.org
226
230
  post_install_message:
227
231
  rdoc_options: []
228
232
  require_paths:
@@ -238,60 +242,59 @@ required_rubygems_version: !ruby/object:Gem::Requirement
238
242
  - !ruby/object:Gem::Version
239
243
  version: '0'
240
244
  requirements: []
241
- rubyforge_project:
242
- rubygems_version: 2.6.14
245
+ rubygems_version: 3.0.3
243
246
  signing_key:
244
247
  specification_version: 4
245
248
  summary: Better HTML for Rails.
246
249
  test_files:
247
- - test/dummy/public/404.html
248
- - test/dummy/public/favicon.ico
249
- - test/dummy/public/422.html
250
- - test/dummy/public/500.html
251
- - test/dummy/config.ru
252
- - test/dummy/bin/setup
253
- - test/dummy/bin/rake
254
- - test/dummy/bin/bundle
255
- - test/dummy/bin/rails
256
- - test/dummy/README.rdoc
257
- - test/dummy/config/database.yml
250
+ - test/better_html/errors_test.rb
251
+ - test/better_html/test_helper/ruby_node_test.rb
252
+ - test/better_html/test_helper/safe_erb/allowed_script_type_test.rb
253
+ - test/better_html/test_helper/safe_erb/no_javascript_tag_helper_test.rb
254
+ - test/better_html/test_helper/safe_erb/script_interpolation_test.rb
255
+ - test/better_html/test_helper/safe_erb/tag_interpolation_test.rb
256
+ - test/better_html/test_helper/safe_erb/no_statements_test.rb
257
+ - test/better_html/test_helper/safe_lodash_tester_test.rb
258
+ - test/better_html/better_erb/implementation_test.rb
259
+ - test/better_html/tokenizer/location_test.rb
260
+ - test/better_html/tokenizer/token_test.rb
261
+ - test/better_html/tokenizer/token_array_test.rb
262
+ - test/better_html/tokenizer/html_lodash_test.rb
263
+ - test/better_html/tokenizer/html_erb_test.rb
264
+ - test/better_html/parser_test.rb
265
+ - test/better_html/helpers_test.rb
266
+ - test/test_helper.rb
267
+ - test/dummy/app/assets/stylesheets/application.css
268
+ - test/dummy/app/assets/javascripts/application.js
269
+ - test/dummy/app/controllers/application_controller.rb
270
+ - test/dummy/app/helpers/application_helper.rb
271
+ - test/dummy/app/views/layouts/application.html.erb
258
272
  - test/dummy/config/secrets.yml
259
- - test/dummy/config/environments/development.rb
260
- - test/dummy/config/environments/production.rb
261
- - test/dummy/config/environments/test.rb
262
273
  - test/dummy/config/initializers/cookies_serializer.rb
263
- - test/dummy/config/initializers/filter_parameter_logging.rb
264
274
  - test/dummy/config/initializers/backtrace_silencers.rb
275
+ - test/dummy/config/initializers/mime_types.rb
276
+ - test/dummy/config/initializers/filter_parameter_logging.rb
265
277
  - test/dummy/config/initializers/wrap_parameters.rb
266
278
  - test/dummy/config/initializers/inflections.rb
267
- - test/dummy/config/initializers/assets.rb
268
279
  - test/dummy/config/initializers/session_store.rb
269
- - test/dummy/config/initializers/mime_types.rb
270
- - test/dummy/config/boot.rb
271
- - test/dummy/config/locales/en.yml
280
+ - test/dummy/config/initializers/assets.rb
281
+ - test/dummy/config/routes.rb
282
+ - test/dummy/config/database.yml
272
283
  - test/dummy/config/environment.rb
284
+ - test/dummy/config/locales/en.yml
285
+ - test/dummy/config/environments/development.rb
286
+ - test/dummy/config/environments/test.rb
287
+ - test/dummy/config/environments/production.rb
288
+ - test/dummy/config/boot.rb
273
289
  - test/dummy/config/application.rb
274
- - test/dummy/config/routes.rb
275
- - test/dummy/app/helpers/application_helper.rb
276
- - test/dummy/app/views/layouts/application.html.erb
277
- - test/dummy/app/controllers/application_controller.rb
278
- - test/dummy/app/assets/stylesheets/application.css
279
- - test/dummy/app/assets/javascripts/application.js
290
+ - test/dummy/config.ru
291
+ - test/dummy/bin/rails
292
+ - test/dummy/bin/rake
293
+ - test/dummy/bin/setup
294
+ - test/dummy/bin/bundle
280
295
  - test/dummy/Rakefile
281
- - test/test_helper.rb
282
- - test/better_html/helpers_test.rb
283
- - test/better_html/errors_test.rb
284
- - test/better_html/parser_test.rb
285
- - test/better_html/better_erb/implementation_test.rb
286
- - test/better_html/test_helper/safe_erb/script_interpolation_test.rb
287
- - test/better_html/test_helper/safe_erb/no_javascript_tag_helper_test.rb
288
- - test/better_html/test_helper/safe_erb/tag_interpolation_test.rb
289
- - test/better_html/test_helper/safe_erb/no_statements_test.rb
290
- - test/better_html/test_helper/safe_erb/allowed_script_type_test.rb
291
- - test/better_html/test_helper/ruby_node_test.rb
292
- - test/better_html/test_helper/safe_lodash_tester_test.rb
293
- - test/better_html/tokenizer/location_test.rb
294
- - test/better_html/tokenizer/html_lodash_test.rb
295
- - test/better_html/tokenizer/html_erb_test.rb
296
- - test/better_html/tokenizer/token_array_test.rb
297
- - test/better_html/tokenizer/token_test.rb
296
+ - test/dummy/public/404.html
297
+ - test/dummy/public/422.html
298
+ - test/dummy/public/favicon.ico
299
+ - test/dummy/public/500.html
300
+ - test/dummy/README.rdoc