hanami-utils 1.3.2 → 1.3.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +28 -0
- data/README.md +2 -3
- data/hanami-utils.gemspec +19 -16
- data/lib/hanami-utils.rb +3 -1
- data/lib/hanami/interactor.rb +57 -31
- data/lib/hanami/logger.rb +12 -12
- data/lib/hanami/logger/colorizer.rb +10 -10
- data/lib/hanami/logger/filter.rb +89 -10
- data/lib/hanami/logger/formatter.rb +4 -4
- data/lib/hanami/utils.rb +12 -10
- data/lib/hanami/utils/basic_object.rb +23 -6
- data/lib/hanami/utils/blank.rb +7 -5
- data/lib/hanami/utils/callbacks.rb +6 -2
- data/lib/hanami/utils/class.rb +8 -8
- data/lib/hanami/utils/class_attribute.rb +4 -2
- data/lib/hanami/utils/deprecation.rb +3 -1
- data/lib/hanami/utils/duplicable.rb +2 -0
- data/lib/hanami/utils/escape.rb +275 -271
- data/lib/hanami/utils/file_list.rb +3 -1
- data/lib/hanami/utils/files.rb +15 -2
- data/lib/hanami/utils/hash.rb +24 -22
- data/lib/hanami/utils/inflector.rb +134 -117
- data/lib/hanami/utils/io.rb +2 -0
- data/lib/hanami/utils/json.rb +5 -3
- data/lib/hanami/utils/kernel.rb +21 -20
- data/lib/hanami/utils/load_paths.rb +6 -4
- data/lib/hanami/utils/path_prefix.rb +6 -4
- data/lib/hanami/utils/query_string.rb +1 -1
- data/lib/hanami/utils/shell_color.rb +9 -9
- data/lib/hanami/utils/string.rb +53 -54
- data/lib/hanami/utils/version.rb +3 -1
- metadata +24 -10
@@ -103,15 +103,15 @@ module Hanami
|
|
103
103
|
|
104
104
|
# @since 0.8.0
|
105
105
|
# @api private
|
106
|
-
def _message_hash(message)
|
106
|
+
def _message_hash(message)
|
107
107
|
case message
|
108
108
|
when Hash
|
109
109
|
@filter.call(message)
|
110
110
|
when Exception
|
111
111
|
Hash[
|
112
|
-
message:
|
112
|
+
message: message.message,
|
113
113
|
backtrace: message.backtrace || [],
|
114
|
-
error:
|
114
|
+
error: message.class
|
115
115
|
]
|
116
116
|
else
|
117
117
|
Hash[message: message]
|
@@ -121,7 +121,7 @@ module Hanami
|
|
121
121
|
# @since 0.8.0
|
122
122
|
# @api private
|
123
123
|
def _format(hash)
|
124
|
-
"#{_line_front_matter(hash.delete(:app), hash.delete(:severity), hash.delete(:time))}#{SEPARATOR}#{_format_message(hash)}"
|
124
|
+
"#{_line_front_matter(hash.delete(:app), hash.delete(:severity), hash.delete(:time))}#{SEPARATOR}#{_format_message(hash)}" # rubocop:disable Layout/LineLength
|
125
125
|
end
|
126
126
|
|
127
127
|
# @since 1.2.0
|
data/lib/hanami/utils.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pathname"
|
2
4
|
|
3
5
|
# Hanami - The web, with simplicity
|
4
6
|
#
|
5
7
|
# @since 0.1.0
|
6
8
|
module Hanami
|
7
|
-
require
|
8
|
-
require
|
9
|
+
require "hanami/utils/version"
|
10
|
+
require "hanami/utils/file_list"
|
9
11
|
|
10
12
|
# Ruby core extentions and Hanami utilities
|
11
13
|
#
|
@@ -13,15 +15,15 @@ module Hanami
|
|
13
15
|
module Utils
|
14
16
|
# @since 0.3.1
|
15
17
|
# @api private
|
16
|
-
HANAMI_JRUBY =
|
18
|
+
HANAMI_JRUBY = "java"
|
17
19
|
|
18
20
|
# @since 0.3.1
|
19
21
|
# @api private
|
20
|
-
HANAMI_RUBINIUS =
|
22
|
+
HANAMI_RUBINIUS = "rbx"
|
21
23
|
|
22
24
|
# Checks if the current VM is JRuby
|
23
25
|
#
|
24
|
-
# @return [TrueClass,FalseClass]
|
26
|
+
# @return [TrueClass,FalseClass] info whether the VM is JRuby or not
|
25
27
|
#
|
26
28
|
# @since 0.3.1
|
27
29
|
# @api private
|
@@ -31,7 +33,7 @@ module Hanami
|
|
31
33
|
|
32
34
|
# Checks if the current VM is Rubinius
|
33
35
|
#
|
34
|
-
# @return [TrueClass,FalseClass]
|
36
|
+
# @return [TrueClass,FalseClass] info whether the VM is Rubinius or not
|
35
37
|
#
|
36
38
|
# @since 0.3.1
|
37
39
|
# @api private
|
@@ -39,7 +41,7 @@ module Hanami
|
|
39
41
|
RUBY_ENGINE == HANAMI_RUBINIUS
|
40
42
|
end
|
41
43
|
|
42
|
-
# Recursively
|
44
|
+
# Recursively requires Ruby files under the given directory.
|
43
45
|
#
|
44
46
|
# If the directory is relative, it implies it's the path from current directory.
|
45
47
|
# If the directory is absolute, it uses as it is.
|
@@ -54,7 +56,7 @@ module Hanami
|
|
54
56
|
for_each_file_in(directory) { |file| require_relative(file) }
|
55
57
|
end
|
56
58
|
|
57
|
-
# Recursively
|
59
|
+
# Recursively reloads Ruby files under the given directory.
|
58
60
|
#
|
59
61
|
# If the directory is relative, it implies it's the path from current directory.
|
60
62
|
# If the directory is absolute, it uses as it is.
|
@@ -87,7 +89,7 @@ module Hanami
|
|
87
89
|
def self.for_each_file_in(directory, &blk)
|
88
90
|
directory = directory.to_s.gsub(%r{(\/|\\)}, File::SEPARATOR)
|
89
91
|
directory = Pathname.new(Dir.pwd).join(directory).to_s
|
90
|
-
directory = File.join(directory,
|
92
|
+
directory = File.join(directory, "**", "*.rb") unless directory =~ /(\*\*)/
|
91
93
|
|
92
94
|
FileList[directory].each(&blk)
|
93
95
|
end
|
@@ -1,10 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Hanami
|
2
4
|
module Utils
|
3
5
|
# BasicObject
|
4
6
|
#
|
5
7
|
# @since 0.3.5
|
6
8
|
class BasicObject < ::BasicObject
|
7
|
-
#
|
9
|
+
# Lookups constants at the top-level namespace, if they are missing in the
|
10
|
+
# current context.
|
11
|
+
#
|
12
|
+
# @param name [Symbol] the constant name
|
13
|
+
#
|
14
|
+
# @return [Object, Module] the constant
|
15
|
+
#
|
16
|
+
# @raise [NameError] if the constant cannot be found
|
17
|
+
#
|
18
|
+
# @since 1.3.4
|
19
|
+
# @api private
|
20
|
+
#
|
21
|
+
# @see https://ruby-doc.org/core/Module.html#method-i-const_missing
|
22
|
+
def self.const_missing(name)
|
23
|
+
::Object.const_get(name)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns the class for debugging purposes.
|
8
27
|
#
|
9
28
|
# @since 0.3.5
|
10
29
|
#
|
@@ -21,17 +40,15 @@ module Hanami
|
|
21
40
|
#
|
22
41
|
# @see http://ruby-doc.org/core/Object.html#method-i-inspect
|
23
42
|
#
|
24
|
-
# rubocop:disable Style/FormatString
|
25
43
|
# rubocop:disable Style/FormatStringToken
|
26
44
|
def inspect
|
27
45
|
"#<#{self.class}:#{'0x0000%x' % (__id__ << 1)}#{__inspect}>"
|
28
46
|
end
|
29
47
|
# rubocop:enable Style/FormatStringToken
|
30
|
-
# rubocop:enable Style/FormatString
|
31
48
|
|
32
49
|
# @!macro [attach] instance_of?(class)
|
33
50
|
#
|
34
|
-
#
|
51
|
+
# Determines if self is an instance of given class or module
|
35
52
|
#
|
36
53
|
# @param class [Class,Module] the class of module to verify
|
37
54
|
#
|
@@ -46,7 +63,7 @@ module Hanami
|
|
46
63
|
|
47
64
|
# @!macro [attach] is_a?(class)
|
48
65
|
#
|
49
|
-
#
|
66
|
+
# Determines if self is of the type of the object class or module
|
50
67
|
#
|
51
68
|
# @param class [Class,Module] the class of module to verify
|
52
69
|
#
|
@@ -61,7 +78,7 @@ module Hanami
|
|
61
78
|
|
62
79
|
# @!macro [attach] kind_of?(class)
|
63
80
|
#
|
64
|
-
#
|
81
|
+
# Determines if self is of the kind of the object class or module
|
65
82
|
#
|
66
83
|
# @param class [Class,Module] the class of module to verify
|
67
84
|
#
|
data/lib/hanami/utils/blank.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Hanami
|
2
4
|
module Utils
|
3
5
|
# Checks for blank
|
@@ -11,7 +13,7 @@ module Hanami
|
|
11
13
|
# @api private
|
12
14
|
STRING_MATCHER = /\A[[:space:]]*\z/.freeze
|
13
15
|
|
14
|
-
# Checks object is blank
|
16
|
+
# Checks if object is blank
|
15
17
|
#
|
16
18
|
# @example Basic Usage
|
17
19
|
# require 'hanami/utils/blank'
|
@@ -25,11 +27,11 @@ module Hanami
|
|
25
27
|
#
|
26
28
|
# @param object the argument
|
27
29
|
#
|
28
|
-
# @return [TrueClass,FalseClass]
|
30
|
+
# @return [TrueClass,FalseClass] info, whether object is blank
|
29
31
|
#
|
30
32
|
# @since 0.8.0
|
31
33
|
# @api private
|
32
|
-
def self.blank?(object)
|
34
|
+
def self.blank?(object)
|
33
35
|
case object
|
34
36
|
when String, ::String
|
35
37
|
STRING_MATCHER === object # rubocop:disable Style/CaseEquality
|
@@ -44,7 +46,7 @@ module Hanami
|
|
44
46
|
end
|
45
47
|
end
|
46
48
|
|
47
|
-
# Checks object is filled
|
49
|
+
# Checks if object is filled
|
48
50
|
#
|
49
51
|
# @example Basic Usage
|
50
52
|
# require 'hanami/utils/blank'
|
@@ -58,7 +60,7 @@ module Hanami
|
|
58
60
|
#
|
59
61
|
# @param object the argument
|
60
62
|
#
|
61
|
-
# @return [TrueClass,FalseClass]
|
63
|
+
# @return [TrueClass,FalseClass] whether the object is filled
|
62
64
|
#
|
63
65
|
# @since 1.0.0
|
64
66
|
# @api private
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Hanami
|
2
4
|
module Utils
|
3
5
|
# Before and After callbacks
|
@@ -10,7 +12,7 @@ module Hanami
|
|
10
12
|
# @since 0.1.0
|
11
13
|
# @private
|
12
14
|
class Chain
|
13
|
-
#
|
15
|
+
# Returns a new chain
|
14
16
|
#
|
15
17
|
# @return [Hanami::Utils::Callbacks::Chain]
|
16
18
|
#
|
@@ -248,7 +250,9 @@ module Hanami
|
|
248
250
|
end
|
249
251
|
|
250
252
|
# Method callback
|
251
|
-
#
|
253
|
+
#
|
254
|
+
# It wraps a symbol or a string representing a method name that is
|
255
|
+
# implemented by the context within it will be called.
|
252
256
|
#
|
253
257
|
# @since 0.1.0
|
254
258
|
# @api private
|
data/lib/hanami/utils/class.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "hanami/utils/deprecation"
|
2
4
|
|
3
5
|
module Hanami
|
4
6
|
module Utils
|
@@ -110,22 +112,21 @@ module Hanami
|
|
110
112
|
# # with missing constant
|
111
113
|
# Hanami::Utils::Class.load_from_pattern!('Unknown') # => raises NameError
|
112
114
|
def self.load_from_pattern!(pattern, namespace = Object)
|
113
|
-
Deprecation.new(
|
115
|
+
Deprecation.new("Hanami::Utils::Class.load_from_pattern! is deprecated, please use Hanami::Utils::Class.load! instead") # rubocop:disable Layout/LineLength
|
114
116
|
|
115
117
|
tokenize(pattern) do |token|
|
116
118
|
begin
|
117
119
|
return namespace.const_get(token, false)
|
118
|
-
rescue NameError # rubocop:disable Lint/
|
120
|
+
rescue NameError # rubocop:disable Lint/SuppressedException
|
119
121
|
end
|
120
122
|
end
|
121
123
|
|
122
|
-
full_name = [(namespace == Object ? nil : namespace), pattern].compact.join(
|
124
|
+
full_name = [(namespace == Object ? nil : namespace), pattern].compact.join("::")
|
123
125
|
raise NameError.new("uninitialized constant #{full_name}")
|
124
126
|
end
|
125
127
|
|
126
|
-
# rubocop:disable Metrics/MethodLength
|
127
128
|
def self.tokenize(pattern)
|
128
|
-
if match = TOKENIZE_REGEXP.match(pattern)
|
129
|
+
if match = TOKENIZE_REGEXP.match(pattern)
|
129
130
|
pre = match.pre_match
|
130
131
|
post = match.post_match
|
131
132
|
tokens = match[1].split(TOKENIZE_SEPARATOR)
|
@@ -138,7 +139,6 @@ module Hanami
|
|
138
139
|
|
139
140
|
nil
|
140
141
|
end
|
141
|
-
# rubocop:enable Metrics/MethodLength
|
142
142
|
|
143
143
|
# Regexp for .tokenize
|
144
144
|
#
|
@@ -150,7 +150,7 @@ module Hanami
|
|
150
150
|
#
|
151
151
|
# @since 1.3.0
|
152
152
|
# @api private
|
153
|
-
TOKENIZE_SEPARATOR =
|
153
|
+
TOKENIZE_SEPARATOR = "|"
|
154
154
|
end
|
155
155
|
end
|
156
156
|
end
|
data/lib/hanami/utils/escape.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Hanami
|
2
4
|
module Utils
|
3
5
|
# HTML escape utilities
|
@@ -30,14 +32,14 @@ module Hanami
|
|
30
32
|
#
|
31
33
|
# @since 0.4.0
|
32
34
|
# @api private
|
33
|
-
REPLACEMENT_HEX =
|
35
|
+
REPLACEMENT_HEX = "fffd"
|
34
36
|
|
35
37
|
# Low hex codes lookup table
|
36
38
|
#
|
37
39
|
# @since 0.4.0
|
38
40
|
# @api private
|
39
41
|
HEX_CODES = (0..255).each_with_object({}) do |c, codes|
|
40
|
-
if (c >= 0x30 && c <= 0x39) || (c >= 0x41 && c <= 0x5A) || (c >= 0x61 && c <= 0x7A)
|
42
|
+
if (c >= 0x30 && c <= 0x39) || (c >= 0x41 && c <= 0x5A) || (c >= 0x61 && c <= 0x7A)
|
41
43
|
codes[c] = nil
|
42
44
|
else
|
43
45
|
codes[c] = c.to_s(HEX_BASE)
|
@@ -53,8 +55,8 @@ module Hanami
|
|
53
55
|
#
|
54
56
|
# @see https://gist.github.com/jodosha/ac5dd54416de744b9600
|
55
57
|
NON_PRINTABLE_CHARS = {
|
56
|
-
0x0
|
57
|
-
0x5
|
58
|
+
0x0 => true, 0x1 => true, 0x2 => true, 0x3 => true, 0x4 => true,
|
59
|
+
0x5 => true, 0x6 => true, 0x7 => true, 0x8 => true, 0x11 => true,
|
58
60
|
0x12 => true, 0x14 => true, 0x15 => true, 0x16 => true, 0x17 => true,
|
59
61
|
0x18 => true, 0x19 => true, 0x1a => true, 0x1b => true, 0x1c => true,
|
60
62
|
0x1d => true, 0x1e => true, 0x1f => true, 0x7f => true, 0x80 => true,
|
@@ -74,12 +76,12 @@ module Hanami
|
|
74
76
|
#
|
75
77
|
# @see Hanami::Utils::Escape.html
|
76
78
|
HTML_CHARS = {
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
'"' =>
|
81
|
-
"'" =>
|
82
|
-
|
79
|
+
"&" => "&",
|
80
|
+
"<" => "<",
|
81
|
+
">" => ">",
|
82
|
+
'"' => """,
|
83
|
+
"'" => "'",
|
84
|
+
"/" => "/"
|
83
85
|
}.freeze
|
84
86
|
|
85
87
|
# Lookup table for safe chars for HTML attributes.
|
@@ -92,7 +94,7 @@ module Hanami
|
|
92
94
|
# @see Lookup::Utils::Escape.html_attribute
|
93
95
|
# @see https://gist.github.com/jodosha/ac5dd54416de744b9600
|
94
96
|
HTML_ATTRIBUTE_SAFE_CHARS = {
|
95
|
-
|
97
|
+
"," => true, "." => true, "-" => true, "_" => true
|
96
98
|
}.freeze
|
97
99
|
|
98
100
|
# Lookup table for HTML attribute escape
|
@@ -102,258 +104,258 @@ module Hanami
|
|
102
104
|
#
|
103
105
|
# @see Hanami::Utils::Escape.html_attribute
|
104
106
|
HTML_ENTITIES = {
|
105
|
-
34
|
106
|
-
38
|
107
|
-
60
|
108
|
-
62
|
109
|
-
160
|
110
|
-
161
|
111
|
-
162
|
112
|
-
163
|
113
|
-
164
|
114
|
-
165
|
115
|
-
166
|
116
|
-
167
|
117
|
-
168
|
118
|
-
169
|
119
|
-
170
|
120
|
-
171
|
121
|
-
172
|
122
|
-
173
|
123
|
-
174
|
124
|
-
175
|
125
|
-
176
|
126
|
-
177
|
127
|
-
178
|
128
|
-
179
|
129
|
-
180
|
130
|
-
181
|
131
|
-
182
|
132
|
-
183
|
133
|
-
184
|
134
|
-
185
|
135
|
-
186
|
136
|
-
187
|
137
|
-
188
|
138
|
-
189
|
139
|
-
190
|
140
|
-
191
|
141
|
-
192
|
142
|
-
193
|
143
|
-
194
|
144
|
-
195
|
145
|
-
196
|
146
|
-
197
|
147
|
-
198
|
148
|
-
199
|
149
|
-
200
|
150
|
-
201
|
151
|
-
202
|
152
|
-
203
|
153
|
-
204
|
154
|
-
205
|
155
|
-
206
|
156
|
-
207
|
157
|
-
208
|
158
|
-
209
|
159
|
-
210
|
160
|
-
211
|
161
|
-
212
|
162
|
-
213
|
163
|
-
214
|
164
|
-
215
|
165
|
-
216
|
166
|
-
217
|
167
|
-
218
|
168
|
-
219
|
169
|
-
220
|
170
|
-
221
|
171
|
-
222
|
172
|
-
223
|
173
|
-
224
|
174
|
-
225
|
175
|
-
226
|
176
|
-
227
|
177
|
-
228
|
178
|
-
229
|
179
|
-
230
|
180
|
-
231
|
181
|
-
232
|
182
|
-
233
|
183
|
-
234
|
184
|
-
235
|
185
|
-
236
|
186
|
-
237
|
187
|
-
238
|
188
|
-
239
|
189
|
-
240
|
190
|
-
241
|
191
|
-
242
|
192
|
-
243
|
193
|
-
244
|
194
|
-
245
|
195
|
-
246
|
196
|
-
247
|
197
|
-
248
|
198
|
-
249
|
199
|
-
250
|
200
|
-
251
|
201
|
-
252
|
202
|
-
253
|
203
|
-
254
|
204
|
-
255
|
205
|
-
338
|
206
|
-
339
|
207
|
-
352
|
208
|
-
353
|
209
|
-
376
|
210
|
-
402
|
211
|
-
710
|
212
|
-
732
|
213
|
-
913
|
214
|
-
914
|
215
|
-
915
|
216
|
-
916
|
217
|
-
917
|
218
|
-
918
|
219
|
-
919
|
220
|
-
920
|
221
|
-
921
|
222
|
-
922
|
223
|
-
923
|
224
|
-
924
|
225
|
-
925
|
226
|
-
926
|
227
|
-
927
|
228
|
-
928
|
229
|
-
929
|
230
|
-
931
|
231
|
-
932
|
232
|
-
933
|
233
|
-
934
|
234
|
-
935
|
235
|
-
936
|
236
|
-
937
|
237
|
-
945
|
238
|
-
946
|
239
|
-
947
|
240
|
-
948
|
241
|
-
949
|
242
|
-
950
|
243
|
-
951
|
244
|
-
952
|
245
|
-
953
|
246
|
-
954
|
247
|
-
955
|
248
|
-
956
|
249
|
-
957
|
250
|
-
958
|
251
|
-
959
|
252
|
-
960
|
253
|
-
961
|
254
|
-
962
|
255
|
-
963
|
256
|
-
964
|
257
|
-
965
|
258
|
-
966
|
259
|
-
967
|
260
|
-
968
|
261
|
-
969
|
262
|
-
977
|
263
|
-
978
|
264
|
-
982
|
265
|
-
8194 =>
|
266
|
-
8195 =>
|
267
|
-
8201 =>
|
268
|
-
8204 =>
|
269
|
-
8205 =>
|
270
|
-
8206 =>
|
271
|
-
8207 =>
|
272
|
-
8211 =>
|
273
|
-
8212 =>
|
274
|
-
8216 =>
|
275
|
-
8217 =>
|
276
|
-
8218 =>
|
277
|
-
8220 =>
|
278
|
-
8221 =>
|
279
|
-
8222 =>
|
280
|
-
8224 =>
|
281
|
-
8225 =>
|
282
|
-
8226 =>
|
283
|
-
8230 =>
|
284
|
-
8240 =>
|
285
|
-
8242 =>
|
286
|
-
8243 =>
|
287
|
-
8249 =>
|
288
|
-
8250 =>
|
289
|
-
8254 =>
|
290
|
-
8260 =>
|
291
|
-
8364 =>
|
292
|
-
8465 =>
|
293
|
-
8472 =>
|
294
|
-
8476 =>
|
295
|
-
8482 =>
|
296
|
-
8501 =>
|
297
|
-
8592 =>
|
298
|
-
8593 =>
|
299
|
-
8594 =>
|
300
|
-
8595 =>
|
301
|
-
8596 =>
|
302
|
-
8629 =>
|
303
|
-
8656 =>
|
304
|
-
8657 =>
|
305
|
-
8658 =>
|
306
|
-
8659 =>
|
307
|
-
8660 =>
|
308
|
-
8704 =>
|
309
|
-
8706 =>
|
310
|
-
8707 =>
|
311
|
-
8709 =>
|
312
|
-
8711 =>
|
313
|
-
8712 =>
|
314
|
-
8713 =>
|
315
|
-
8715 =>
|
316
|
-
8719 =>
|
317
|
-
8721 =>
|
318
|
-
8722 =>
|
319
|
-
8727 =>
|
320
|
-
8730 =>
|
321
|
-
8733 =>
|
322
|
-
8734 =>
|
323
|
-
8736 =>
|
324
|
-
8743 =>
|
325
|
-
8744 =>
|
326
|
-
8745 =>
|
327
|
-
8746 =>
|
328
|
-
8747 =>
|
329
|
-
8756 =>
|
330
|
-
8764 =>
|
331
|
-
8773 =>
|
332
|
-
8776 =>
|
333
|
-
8800 =>
|
334
|
-
8801 =>
|
335
|
-
8804 =>
|
336
|
-
8805 =>
|
337
|
-
8834 =>
|
338
|
-
8835 =>
|
339
|
-
8836 =>
|
340
|
-
8838 =>
|
341
|
-
8839 =>
|
342
|
-
8853 =>
|
343
|
-
8855 =>
|
344
|
-
8869 =>
|
345
|
-
8901 =>
|
346
|
-
8968 =>
|
347
|
-
8969 =>
|
348
|
-
8970 =>
|
349
|
-
8971 =>
|
350
|
-
9001 =>
|
351
|
-
9002 =>
|
352
|
-
9674 =>
|
353
|
-
9824 =>
|
354
|
-
9827 =>
|
355
|
-
9829 =>
|
356
|
-
9830 =>
|
107
|
+
34 => "quot", # quotation mark
|
108
|
+
38 => "amp", # ampersand
|
109
|
+
60 => "lt", # less-than sign
|
110
|
+
62 => "gt", # greater-than sign
|
111
|
+
160 => "nbsp", # no-break space
|
112
|
+
161 => "iexcl", # inverted exclamation mark
|
113
|
+
162 => "cent", # cent sign
|
114
|
+
163 => "pound", # pound sign
|
115
|
+
164 => "curren", # currency sign
|
116
|
+
165 => "yen", # yen sign
|
117
|
+
166 => "brvbar", # broken bar
|
118
|
+
167 => "sect", # section sign
|
119
|
+
168 => "uml", # diaeresis
|
120
|
+
169 => "copy", # copyright sign
|
121
|
+
170 => "ordf", # feminine ordinal indicator
|
122
|
+
171 => "laquo", # left-pointing double angle quotation mark
|
123
|
+
172 => "not", # not sign
|
124
|
+
173 => "shy", # soft hyphen
|
125
|
+
174 => "reg", # registered sign
|
126
|
+
175 => "macr", # macron
|
127
|
+
176 => "deg", # degree sign
|
128
|
+
177 => "plusmn", # plus-minus sign
|
129
|
+
178 => "sup2", # superscript two
|
130
|
+
179 => "sup3", # superscript three
|
131
|
+
180 => "acute", # acute accent
|
132
|
+
181 => "micro", # micro sign
|
133
|
+
182 => "para", # pilcrow sign
|
134
|
+
183 => "middot", # middle dot
|
135
|
+
184 => "cedil", # cedilla
|
136
|
+
185 => "sup1", # superscript one
|
137
|
+
186 => "ordm", # masculine ordinal indicator
|
138
|
+
187 => "raquo", # right-pointing double angle quotation mark
|
139
|
+
188 => "frac14", # vulgar fraction one quarter
|
140
|
+
189 => "frac12", # vulgar fraction one half
|
141
|
+
190 => "frac34", # vulgar fraction three quarters
|
142
|
+
191 => "iquest", # inverted question mark
|
143
|
+
192 => "Agrave", # Latin capital letter a with grave
|
144
|
+
193 => "Aacute", # Latin capital letter a with acute
|
145
|
+
194 => "Acirc", # Latin capital letter a with circumflex
|
146
|
+
195 => "Atilde", # Latin capital letter a with tilde
|
147
|
+
196 => "Auml", # Latin capital letter a with diaeresis
|
148
|
+
197 => "Aring", # Latin capital letter a with ring above
|
149
|
+
198 => "AElig", # Latin capital letter ae
|
150
|
+
199 => "Ccedil", # Latin capital letter c with cedilla
|
151
|
+
200 => "Egrave", # Latin capital letter e with grave
|
152
|
+
201 => "Eacute", # Latin capital letter e with acute
|
153
|
+
202 => "Ecirc", # Latin capital letter e with circumflex
|
154
|
+
203 => "Euml", # Latin capital letter e with diaeresis
|
155
|
+
204 => "Igrave", # Latin capital letter i with grave
|
156
|
+
205 => "Iacute", # Latin capital letter i with acute
|
157
|
+
206 => "Icirc", # Latin capital letter i with circumflex
|
158
|
+
207 => "Iuml", # Latin capital letter i with diaeresis
|
159
|
+
208 => "ETH", # Latin capital letter eth
|
160
|
+
209 => "Ntilde", # Latin capital letter n with tilde
|
161
|
+
210 => "Ograve", # Latin capital letter o with grave
|
162
|
+
211 => "Oacute", # Latin capital letter o with acute
|
163
|
+
212 => "Ocirc", # Latin capital letter o with circumflex
|
164
|
+
213 => "Otilde", # Latin capital letter o with tilde
|
165
|
+
214 => "Ouml", # Latin capital letter o with diaeresis
|
166
|
+
215 => "times", # multiplication sign
|
167
|
+
216 => "Oslash", # Latin capital letter o with stroke
|
168
|
+
217 => "Ugrave", # Latin capital letter u with grave
|
169
|
+
218 => "Uacute", # Latin capital letter u with acute
|
170
|
+
219 => "Ucirc", # Latin capital letter u with circumflex
|
171
|
+
220 => "Uuml", # Latin capital letter u with diaeresis
|
172
|
+
221 => "Yacute", # Latin capital letter y with acute
|
173
|
+
222 => "THORN", # Latin capital letter thorn
|
174
|
+
223 => "szlig", # Latin small letter sharp sXCOMMAX German Eszett
|
175
|
+
224 => "agrave", # Latin small letter a with grave
|
176
|
+
225 => "aacute", # Latin small letter a with acute
|
177
|
+
226 => "acirc", # Latin small letter a with circumflex
|
178
|
+
227 => "atilde", # Latin small letter a with tilde
|
179
|
+
228 => "auml", # Latin small letter a with diaeresis
|
180
|
+
229 => "aring", # Latin small letter a with ring above
|
181
|
+
230 => "aelig", # Latin lowercase ligature ae
|
182
|
+
231 => "ccedil", # Latin small letter c with cedilla
|
183
|
+
232 => "egrave", # Latin small letter e with grave
|
184
|
+
233 => "eacute", # Latin small letter e with acute
|
185
|
+
234 => "ecirc", # Latin small letter e with circumflex
|
186
|
+
235 => "euml", # Latin small letter e with diaeresis
|
187
|
+
236 => "igrave", # Latin small letter i with grave
|
188
|
+
237 => "iacute", # Latin small letter i with acute
|
189
|
+
238 => "icirc", # Latin small letter i with circumflex
|
190
|
+
239 => "iuml", # Latin small letter i with diaeresis
|
191
|
+
240 => "eth", # Latin small letter eth
|
192
|
+
241 => "ntilde", # Latin small letter n with tilde
|
193
|
+
242 => "ograve", # Latin small letter o with grave
|
194
|
+
243 => "oacute", # Latin small letter o with acute
|
195
|
+
244 => "ocirc", # Latin small letter o with circumflex
|
196
|
+
245 => "otilde", # Latin small letter o with tilde
|
197
|
+
246 => "ouml", # Latin small letter o with diaeresis
|
198
|
+
247 => "divide", # division sign
|
199
|
+
248 => "oslash", # Latin small letter o with stroke
|
200
|
+
249 => "ugrave", # Latin small letter u with grave
|
201
|
+
250 => "uacute", # Latin small letter u with acute
|
202
|
+
251 => "ucirc", # Latin small letter u with circumflex
|
203
|
+
252 => "uuml", # Latin small letter u with diaeresis
|
204
|
+
253 => "yacute", # Latin small letter y with acute
|
205
|
+
254 => "thorn", # Latin small letter thorn
|
206
|
+
255 => "yuml", # Latin small letter y with diaeresis
|
207
|
+
338 => "OElig", # Latin capital ligature oe
|
208
|
+
339 => "oelig", # Latin small ligature oe
|
209
|
+
352 => "Scaron", # Latin capital letter s with caron
|
210
|
+
353 => "scaron", # Latin small letter s with caron
|
211
|
+
376 => "Yuml", # Latin capital letter y with diaeresis
|
212
|
+
402 => "fnof", # Latin small letter f with hook
|
213
|
+
710 => "circ", # modifier letter circumflex accent
|
214
|
+
732 => "tilde", # small tilde
|
215
|
+
913 => "Alpha", # Greek capital letter alpha
|
216
|
+
914 => "Beta", # Greek capital letter beta
|
217
|
+
915 => "Gamma", # Greek capital letter gamma
|
218
|
+
916 => "Delta", # Greek capital letter delta
|
219
|
+
917 => "Epsilon", # Greek capital letter epsilon
|
220
|
+
918 => "Zeta", # Greek capital letter zeta
|
221
|
+
919 => "Eta", # Greek capital letter eta
|
222
|
+
920 => "Theta", # Greek capital letter theta
|
223
|
+
921 => "Iota", # Greek capital letter iota
|
224
|
+
922 => "Kappa", # Greek capital letter kappa
|
225
|
+
923 => "Lambda", # Greek capital letter lambda
|
226
|
+
924 => "Mu", # Greek capital letter mu
|
227
|
+
925 => "Nu", # Greek capital letter nu
|
228
|
+
926 => "Xi", # Greek capital letter xi
|
229
|
+
927 => "Omicron", # Greek capital letter omicron
|
230
|
+
928 => "Pi", # Greek capital letter pi
|
231
|
+
929 => "Rho", # Greek capital letter rho
|
232
|
+
931 => "Sigma", # Greek capital letter sigma
|
233
|
+
932 => "Tau", # Greek capital letter tau
|
234
|
+
933 => "Upsilon", # Greek capital letter upsilon
|
235
|
+
934 => "Phi", # Greek capital letter phi
|
236
|
+
935 => "Chi", # Greek capital letter chi
|
237
|
+
936 => "Psi", # Greek capital letter psi
|
238
|
+
937 => "Omega", # Greek capital letter omega
|
239
|
+
945 => "alpha", # Greek small letter alpha
|
240
|
+
946 => "beta", # Greek small letter beta
|
241
|
+
947 => "gamma", # Greek small letter gamma
|
242
|
+
948 => "delta", # Greek small letter delta
|
243
|
+
949 => "epsilon", # Greek small letter epsilon
|
244
|
+
950 => "zeta", # Greek small letter zeta
|
245
|
+
951 => "eta", # Greek small letter eta
|
246
|
+
952 => "theta", # Greek small letter theta
|
247
|
+
953 => "iota", # Greek small letter iota
|
248
|
+
954 => "kappa", # Greek small letter kappa
|
249
|
+
955 => "lambda", # Greek small letter lambda
|
250
|
+
956 => "mu", # Greek small letter mu
|
251
|
+
957 => "nu", # Greek small letter nu
|
252
|
+
958 => "xi", # Greek small letter xi
|
253
|
+
959 => "omicron", # Greek small letter omicron
|
254
|
+
960 => "pi", # Greek small letter pi
|
255
|
+
961 => "rho", # Greek small letter rho
|
256
|
+
962 => "sigmaf", # Greek small letter final sigma
|
257
|
+
963 => "sigma", # Greek small letter sigma
|
258
|
+
964 => "tau", # Greek small letter tau
|
259
|
+
965 => "upsilon", # Greek small letter upsilon
|
260
|
+
966 => "phi", # Greek small letter phi
|
261
|
+
967 => "chi", # Greek small letter chi
|
262
|
+
968 => "psi", # Greek small letter psi
|
263
|
+
969 => "omega", # Greek small letter omega
|
264
|
+
977 => "thetasym", # Greek theta symbol
|
265
|
+
978 => "upsih", # Greek upsilon with hook symbol
|
266
|
+
982 => "piv", # Greek pi symbol
|
267
|
+
8194 => "ensp", # en space
|
268
|
+
8195 => "emsp", # em space
|
269
|
+
8201 => "thinsp", # thin space
|
270
|
+
8204 => "zwnj", # zero width non-joiner
|
271
|
+
8205 => "zwj", # zero width joiner
|
272
|
+
8206 => "lrm", # left-to-right mark
|
273
|
+
8207 => "rlm", # right-to-left mark
|
274
|
+
8211 => "ndash", # en dash
|
275
|
+
8212 => "mdash", # em dash
|
276
|
+
8216 => "lsquo", # left single quotation mark
|
277
|
+
8217 => "rsquo", # right single quotation mark
|
278
|
+
8218 => "sbquo", # single low-9 quotation mark
|
279
|
+
8220 => "ldquo", # left double quotation mark
|
280
|
+
8221 => "rdquo", # right double quotation mark
|
281
|
+
8222 => "bdquo", # double low-9 quotation mark
|
282
|
+
8224 => "dagger", # dagger
|
283
|
+
8225 => "Dagger", # double dagger
|
284
|
+
8226 => "bull", # bullet
|
285
|
+
8230 => "hellip", # horizontal ellipsis
|
286
|
+
8240 => "permil", # per mille sign
|
287
|
+
8242 => "prime", # prime
|
288
|
+
8243 => "Prime", # double prime
|
289
|
+
8249 => "lsaquo", # single left-pointing angle quotation mark
|
290
|
+
8250 => "rsaquo", # single right-pointing angle quotation mark
|
291
|
+
8254 => "oline", # overline
|
292
|
+
8260 => "frasl", # fraction slash
|
293
|
+
8364 => "euro", # euro sign
|
294
|
+
8465 => "image", # black-letter capital i
|
295
|
+
8472 => "weierp", # script capital pXCOMMAX Weierstrass p
|
296
|
+
8476 => "real", # black-letter capital r
|
297
|
+
8482 => "trade", # trademark sign
|
298
|
+
8501 => "alefsym", # alef symbol
|
299
|
+
8592 => "larr", # leftwards arrow
|
300
|
+
8593 => "uarr", # upwards arrow
|
301
|
+
8594 => "rarr", # rightwards arrow
|
302
|
+
8595 => "darr", # downwards arrow
|
303
|
+
8596 => "harr", # left right arrow
|
304
|
+
8629 => "crarr", # downwards arrow with corner leftwards
|
305
|
+
8656 => "lArr", # leftwards double arrow
|
306
|
+
8657 => "uArr", # upwards double arrow
|
307
|
+
8658 => "rArr", # rightwards double arrow
|
308
|
+
8659 => "dArr", # downwards double arrow
|
309
|
+
8660 => "hArr", # left right double arrow
|
310
|
+
8704 => "forall", # for all
|
311
|
+
8706 => "part", # partial differential
|
312
|
+
8707 => "exist", # there exists
|
313
|
+
8709 => "empty", # empty set
|
314
|
+
8711 => "nabla", # nabla
|
315
|
+
8712 => "isin", # element of
|
316
|
+
8713 => "notin", # not an element of
|
317
|
+
8715 => "ni", # contains as member
|
318
|
+
8719 => "prod", # n-ary product
|
319
|
+
8721 => "sum", # n-ary summation
|
320
|
+
8722 => "minus", # minus sign
|
321
|
+
8727 => "lowast", # asterisk operator
|
322
|
+
8730 => "radic", # square root
|
323
|
+
8733 => "prop", # proportional to
|
324
|
+
8734 => "infin", # infinity
|
325
|
+
8736 => "ang", # angle
|
326
|
+
8743 => "and", # logical and
|
327
|
+
8744 => "or", # logical or
|
328
|
+
8745 => "cap", # intersection
|
329
|
+
8746 => "cup", # union
|
330
|
+
8747 => "int", # integral
|
331
|
+
8756 => "there4", # therefore
|
332
|
+
8764 => "sim", # tilde operator
|
333
|
+
8773 => "cong", # congruent to
|
334
|
+
8776 => "asymp", # almost equal to
|
335
|
+
8800 => "ne", # not equal to
|
336
|
+
8801 => "equiv", # identical toXCOMMAX equivalent to
|
337
|
+
8804 => "le", # less-than or equal to
|
338
|
+
8805 => "ge", # greater-than or equal to
|
339
|
+
8834 => "sub", # subset of
|
340
|
+
8835 => "sup", # superset of
|
341
|
+
8836 => "nsub", # not a subset of
|
342
|
+
8838 => "sube", # subset of or equal to
|
343
|
+
8839 => "supe", # superset of or equal to
|
344
|
+
8853 => "oplus", # circled plus
|
345
|
+
8855 => "otimes", # circled times
|
346
|
+
8869 => "perp", # up tack
|
347
|
+
8901 => "sdot", # dot operator
|
348
|
+
8968 => "lceil", # left ceiling
|
349
|
+
8969 => "rceil", # right ceiling
|
350
|
+
8970 => "lfloor", # left floor
|
351
|
+
8971 => "rfloor", # right floor
|
352
|
+
9001 => "lang", # left-pointing angle bracket
|
353
|
+
9002 => "rang", # right-pointing angle bracket
|
354
|
+
9674 => "loz", # lozenge
|
355
|
+
9824 => "spades", # black spade suit
|
356
|
+
9827 => "clubs", # black club suit
|
357
|
+
9829 => "hearts", # black heart suit
|
358
|
+
9830 => "diams" # black diamond suit
|
357
359
|
}.freeze
|
358
360
|
|
359
361
|
# Allowed URL schemes
|
@@ -368,8 +370,10 @@ module Hanami
|
|
368
370
|
#
|
369
371
|
# It's marked with this special class for two reasons:
|
370
372
|
#
|
371
|
-
# * Don't double escape the same string (this is for `Hanami::Helpers`
|
372
|
-
#
|
373
|
+
# * Don't double escape the same string (this is for `Hanami::Helpers`
|
374
|
+
# compatibility)
|
375
|
+
# * Leave open the possibility to developers to mark a string as safe
|
376
|
+
# with an higher API (eg. `#raw` in `Hanami::View` or `Hanami::Helpers`)
|
373
377
|
#
|
374
378
|
# @since 0.4.0
|
375
379
|
# @api private
|
@@ -397,7 +401,7 @@ module Hanami
|
|
397
401
|
end
|
398
402
|
end
|
399
403
|
|
400
|
-
#
|
404
|
+
# Escapes HTML contents
|
401
405
|
#
|
402
406
|
# This MUST be used only for tag contents.
|
403
407
|
# Please use `html_attribute` for escaping HTML attributes.
|
@@ -430,7 +434,7 @@ module Hanami
|
|
430
434
|
result
|
431
435
|
end
|
432
436
|
|
433
|
-
#
|
437
|
+
# Escapes HTML attributes
|
434
438
|
#
|
435
439
|
# This can be used both for HTML attributes and contents.
|
436
440
|
# Please note that this is more computational expensive.
|
@@ -463,7 +467,7 @@ module Hanami
|
|
463
467
|
result
|
464
468
|
end
|
465
469
|
|
466
|
-
#
|
470
|
+
# Escapes URL for HTML attributes (href, src, etc..).
|
467
471
|
#
|
468
472
|
# It extracts from the given input the first valid URL that matches the
|
469
473
|
# whitelisted schemes (default: http, https and mailto).
|
@@ -521,7 +525,7 @@ module Hanami
|
|
521
525
|
class << self
|
522
526
|
private
|
523
527
|
|
524
|
-
#
|
528
|
+
# Encodes the given string into UTF-8
|
525
529
|
#
|
526
530
|
# @param input [String] the input
|
527
531
|
#
|
@@ -530,7 +534,7 @@ module Hanami
|
|
530
534
|
# @since 0.4.0
|
531
535
|
# @api private
|
532
536
|
def encode(input)
|
533
|
-
return
|
537
|
+
return "" if input.nil?
|
534
538
|
|
535
539
|
input.to_s.encode(Encoding::UTF_8)
|
536
540
|
rescue Encoding::UndefinedConversionError
|
@@ -555,7 +559,7 @@ module Hanami
|
|
555
559
|
|
556
560
|
hex = REPLACEMENT_HEX if NON_PRINTABLE_CHARS[code]
|
557
561
|
|
558
|
-
if entity = HTML_ENTITIES[code]
|
562
|
+
if entity = HTML_ENTITIES[code]
|
559
563
|
"&#{entity};"
|
560
564
|
else
|
561
565
|
"&#x#{hex};"
|