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 +5 -5
- data/lib/better_html/better_erb.rb +12 -6
- data/lib/better_html/config.rb +5 -5
- data/lib/better_html/test_helper/ruby_node.rb +1 -0
- data/lib/better_html/test_helper/safe_erb_tester.rb +2 -2
- data/lib/better_html/test_helper/safe_lodash_tester.rb +1 -0
- data/lib/better_html/tokenizer/base_erb.rb +5 -5
- data/lib/better_html/tokenizer/html_lodash.rb +1 -0
- data/lib/better_html/version.rb +1 -1
- data/test/better_html/test_helper/safe_erb/allowed_script_type_test.rb +1 -0
- data/test/better_html/test_helper/safe_erb/no_statements_test.rb +1 -0
- data/test/better_html/tokenizer/token_array_test.rb +1 -0
- data/test/test_helper.rb +0 -1
- metadata +50 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e8dc392542e380b0d3cb63c331cf0524f1b016f15fb99c907e8fd951fb22eae7
|
4
|
+
data.tar.gz: 3393a92593172019c1180c9ca3ed8dc81c9c043954b9d0a221dd82dcd399f8dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 =
|
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(
|
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 =>
|
67
|
+
:escape => escape,
|
62
68
|
:trim => (self.class.erb_trim_mode == "-")
|
63
69
|
)
|
64
70
|
generator.validate! if generator.respond_to?(:validate!)
|
data/lib/better_html/config.rb
CHANGED
@@ -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 }
|
@@ -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
|
-
|
55
|
+
tester_klass.new(parser)
|
56
56
|
end
|
57
57
|
testers.each(&:validate)
|
58
58
|
errors = testers.map(&:errors).flatten
|
@@ -49,20 +49,20 @@ module BetterHtml
|
|
49
49
|
def add_erb_tokens(ltrim, indicator, code, rtrim)
|
50
50
|
pos = current_position
|
51
51
|
|
52
|
-
|
52
|
+
add_token(:erb_begin, pos, pos + 2)
|
53
53
|
pos += 2
|
54
54
|
|
55
55
|
if ltrim
|
56
|
-
|
56
|
+
add_token(:trim, pos, pos + ltrim.length)
|
57
57
|
pos += ltrim.length
|
58
58
|
end
|
59
59
|
|
60
60
|
if indicator
|
61
|
-
|
61
|
+
add_token(:indicator, pos, pos + indicator.length)
|
62
62
|
pos += indicator.length
|
63
63
|
end
|
64
64
|
|
65
|
-
|
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
|
-
|
73
|
+
add_token(:erb_end, pos, pos + 2)
|
74
74
|
end
|
75
75
|
|
76
76
|
def add_token(type, begin_pos, end_pos)
|
data/lib/better_html/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
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.
|
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:
|
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
|
-
|
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/
|
248
|
-
- test/
|
249
|
-
- test/
|
250
|
-
- test/
|
251
|
-
- test/
|
252
|
-
- test/
|
253
|
-
- test/
|
254
|
-
- test/
|
255
|
-
- test/
|
256
|
-
- test/
|
257
|
-
- test/
|
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/
|
270
|
-
- test/dummy/config/
|
271
|
-
- test/dummy/config/
|
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
|
275
|
-
- test/dummy/
|
276
|
-
- test/dummy/
|
277
|
-
- test/dummy/
|
278
|
-
- test/dummy/
|
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/
|
282
|
-
- test/
|
283
|
-
- test/
|
284
|
-
- test/
|
285
|
-
- test/
|
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
|