phlex 2.4.0 → 2.4.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 +4 -4
- data/lib/phlex/html.rb +1 -1
- data/lib/phlex/sgml/attributes.rb +33 -4
- data/lib/phlex/svg.rb +1 -1
- data/lib/phlex/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: abdf62bcb21b9c00118dc8fa4f1c96d510caecc15eebf4539b5655c3ab94e057
|
|
4
|
+
data.tar.gz: e88808653a12b00adbb4980e07994b379bb871cabd4652c9e19bb76ef87dc0f0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f6568b33898b323c45e86405f3369816262195e4da70b9b94405779fd6728307b7c785ee53392bc1717ee2de26dad5029ec47b2f6753cb80ed4880a4cd15c97e
|
|
7
|
+
data.tar.gz: '09cdec83ffabbe16b7e2895f1964f1cc29217c89b93a1a7848c982ec1d0329d101ad165b165f0c98638daf9c0b5bc3072cf671661e41d139a9ffe5f5069f9055'
|
data/lib/phlex/html.rb
CHANGED
|
@@ -55,7 +55,7 @@ class Phlex::HTML < Phlex::SGML
|
|
|
55
55
|
raise Phlex::ArgumentError.new("Expected the tag name to be a Symbol.")
|
|
56
56
|
end
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
if (tag = StandardElements.__registered_elements__[name]) || ((tag = name.name.tr("_", "-")).include?("-") && tag.match?(/\A[a-z0-9-]+\z/))
|
|
59
59
|
if attributes.length > 0 # with attributes
|
|
60
60
|
if block_given # with content block
|
|
61
61
|
buffer << "<#{tag}" << (Phlex::ATTRIBUTE_CACHE[attributes] ||= Phlex::SGML::Attributes.generate_attributes(attributes)) << ">"
|
|
@@ -4,7 +4,13 @@ module Phlex::SGML::Attributes
|
|
|
4
4
|
extend self
|
|
5
5
|
|
|
6
6
|
UNSAFE_ATTRIBUTES = Set.new(%w[srcdoc sandbox http-equiv]).freeze
|
|
7
|
-
REF_ATTRIBUTES = Set.new(%w[href src action formaction lowsrc dynsrc background ping]).freeze
|
|
7
|
+
REF_ATTRIBUTES = Set.new(%w[href src action formaction lowsrc dynsrc background ping xlinkhref]).freeze
|
|
8
|
+
NAMED_CHARACTER_REFERENCES = {
|
|
9
|
+
"colon" => ":",
|
|
10
|
+
"tab" => "\t",
|
|
11
|
+
"newline" => "\n",
|
|
12
|
+
}.freeze
|
|
13
|
+
UNSAFE_ATTRIBUTE_NAME_CHARS = %r([<>&"'/=\s\x00])
|
|
8
14
|
|
|
9
15
|
def generate_attributes(attributes, buffer = +"")
|
|
10
16
|
attributes.each do |k, v|
|
|
@@ -68,7 +74,9 @@ module Phlex::SGML::Attributes
|
|
|
68
74
|
if value != true && REF_ATTRIBUTES.include?(normalized_name)
|
|
69
75
|
case value
|
|
70
76
|
when String
|
|
71
|
-
|
|
77
|
+
decoded_value = decode_html_character_references(value)
|
|
78
|
+
|
|
79
|
+
if decoded_value.downcase.delete("^a-z:").start_with?("javascript:")
|
|
72
80
|
# We just ignore these because they were likely not specified by the developer.
|
|
73
81
|
next
|
|
74
82
|
end
|
|
@@ -86,7 +94,7 @@ module Phlex::SGML::Attributes
|
|
|
86
94
|
end
|
|
87
95
|
end
|
|
88
96
|
|
|
89
|
-
if name.match?(
|
|
97
|
+
if name.match?(UNSAFE_ATTRIBUTE_NAME_CHARS)
|
|
90
98
|
raise Phlex::ArgumentError.new("Unsafe attribute name detected: #{k}.")
|
|
91
99
|
end
|
|
92
100
|
|
|
@@ -122,7 +130,7 @@ module Phlex::SGML::Attributes
|
|
|
122
130
|
else raise Phlex::ArgumentError.new("Attribute keys should be Strings or Symbols")
|
|
123
131
|
end
|
|
124
132
|
|
|
125
|
-
if name.match?(
|
|
133
|
+
if name.match?(UNSAFE_ATTRIBUTE_NAME_CHARS)
|
|
126
134
|
raise Phlex::ArgumentError.new("Unsafe attribute name detected: #{k}.")
|
|
127
135
|
end
|
|
128
136
|
end
|
|
@@ -160,6 +168,27 @@ module Phlex::SGML::Attributes
|
|
|
160
168
|
end
|
|
161
169
|
end
|
|
162
170
|
|
|
171
|
+
def decode_html_character_references(value)
|
|
172
|
+
value
|
|
173
|
+
.gsub(/&#x([0-9a-f]+);?/i) {
|
|
174
|
+
begin
|
|
175
|
+
[$1.to_i(16)].pack("U*")
|
|
176
|
+
rescue
|
|
177
|
+
""
|
|
178
|
+
end
|
|
179
|
+
}
|
|
180
|
+
.gsub(/&#(\d+);?/) {
|
|
181
|
+
begin
|
|
182
|
+
[$1.to_i].pack("U*")
|
|
183
|
+
rescue
|
|
184
|
+
""
|
|
185
|
+
end
|
|
186
|
+
}
|
|
187
|
+
.gsub(/&([a-z][a-z0-9]+);?/i) {
|
|
188
|
+
NAMED_CHARACTER_REFERENCES[$1.downcase] || ""
|
|
189
|
+
}
|
|
190
|
+
end
|
|
191
|
+
|
|
163
192
|
def generate_nested_tokens(tokens, sep = " ", gsub_from = nil, gsub_to = "")
|
|
164
193
|
buffer = +""
|
|
165
194
|
|
data/lib/phlex/svg.rb
CHANGED
|
@@ -41,7 +41,7 @@ class Phlex::SVG < Phlex::SGML
|
|
|
41
41
|
raise Phlex::ArgumentError.new("Expected the tag name to be a Symbol.")
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
if (tag = StandardElements.__registered_elements__[name]) || ((tag = name.name.tr("_", "-")).include?("-") && tag.match?(/\A[a-z0-9-]+\z/))
|
|
45
45
|
if attributes.length > 0 # with attributes
|
|
46
46
|
if block_given # with content block
|
|
47
47
|
buffer << "<#{tag}" << (Phlex::ATTRIBUTE_CACHE[attributes] ||= Phlex::SGML::Attributes.generate_attributes(attributes)) << ">"
|
data/lib/phlex/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: phlex
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.4.
|
|
4
|
+
version: 2.4.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Joel Drapper
|
|
8
8
|
- Will Cosgrove
|
|
9
|
+
autorequire:
|
|
9
10
|
bindir: bin
|
|
10
11
|
cert_chain: []
|
|
11
|
-
date:
|
|
12
|
+
date: 2026-02-06 00:00:00.000000000 Z
|
|
12
13
|
dependencies:
|
|
13
14
|
- !ruby/object:Gem::Dependency
|
|
14
15
|
name: zeitwerk
|
|
@@ -85,6 +86,7 @@ metadata:
|
|
|
85
86
|
changelog_uri: https://github.com/phlex-ruby/phlex/releases
|
|
86
87
|
funding_uri: https://github.com/sponsors/joeldrapper
|
|
87
88
|
rubygems_mfa_required: 'true'
|
|
89
|
+
post_install_message:
|
|
88
90
|
rdoc_options: []
|
|
89
91
|
require_paths:
|
|
90
92
|
- lib
|
|
@@ -99,7 +101,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
99
101
|
- !ruby/object:Gem::Version
|
|
100
102
|
version: '0'
|
|
101
103
|
requirements: []
|
|
102
|
-
rubygems_version:
|
|
104
|
+
rubygems_version: 3.5.3
|
|
105
|
+
signing_key:
|
|
103
106
|
specification_version: 4
|
|
104
107
|
summary: Object-oriented views in Ruby.
|
|
105
108
|
test_files: []
|