phlex 1.11.0 → 1.11.2
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/sgml.rb +77 -3
- data/lib/phlex/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cbcab903b6e369e32bd8a3cf6645bde4b53284e11d8110d3cf18f7370e2eea83
|
|
4
|
+
data.tar.gz: a38a1e0bfd2ff5ad3940b894ee2efd9c72803412c4a909e0cdc7b5d3eed0cbfe
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: eda6a5b7939f09ffe5926187f24e5c2af792845eeed880f5f6765a4a365e3f3539673bbe502dd557a2e709c791a36412adc12ab960fd1822ff5bbf3c089bc886
|
|
7
|
+
data.tar.gz: db59525d096e1398a4d6880f74c6d9b6d64167c101c9a7959d4ec265eb89b602d05ff7f117daadcf75c56cf7065181ac683c648f6120ba938f38577a68c6bbd6
|
data/lib/phlex/sgml.rb
CHANGED
|
@@ -4,6 +4,22 @@ module Phlex
|
|
|
4
4
|
# **Standard Generalized Markup Language** for behaviour common to {HTML} and {SVG}.
|
|
5
5
|
class SGML
|
|
6
6
|
include Helpers
|
|
7
|
+
# SVG animation elements, such as `set` and `animate`, write `to`, `from`,
|
|
8
|
+
# `by` and `values` to the attribute their `attributeName` names, which can
|
|
9
|
+
# be `href`, so those are checked as references too.
|
|
10
|
+
REF_ATTRIBUTES = Set.new(%w[href src action formaction lowsrc dynsrc background ping xlinkhref to from by values]).freeze
|
|
11
|
+
# References whose value is a `;`-separated list, any entry of which can be used.
|
|
12
|
+
REF_LIST_ATTRIBUTES = Set.new(%w[values]).freeze
|
|
13
|
+
# `data` takes a URL on `object`. A Hash given to it expands into `data-*`
|
|
14
|
+
# attributes instead, and isn't checked.
|
|
15
|
+
DATA_ATTRIBUTE = "data"
|
|
16
|
+
NAMED_CHARACTER_REFERENCES = {
|
|
17
|
+
"colon" => ":",
|
|
18
|
+
"tab" => "\t",
|
|
19
|
+
"newline" => "\n",
|
|
20
|
+
"semi" => ";",
|
|
21
|
+
}.freeze
|
|
22
|
+
UNSAFE_ATTRIBUTE_NAME_CHARS = %r([<>&"'/=\s\x00])
|
|
7
23
|
|
|
8
24
|
class << self
|
|
9
25
|
# Render the view to a String. Arguments are delegated to {.new}.
|
|
@@ -421,6 +437,27 @@ module Phlex
|
|
|
421
437
|
buffer
|
|
422
438
|
end
|
|
423
439
|
|
|
440
|
+
def decode_html_character_references(value)
|
|
441
|
+
value
|
|
442
|
+
.gsub(/&#x([0-9a-f]+);?/i) {
|
|
443
|
+
begin
|
|
444
|
+
[$1.to_i(16)].pack("U*")
|
|
445
|
+
rescue
|
|
446
|
+
""
|
|
447
|
+
end
|
|
448
|
+
}
|
|
449
|
+
.gsub(/&#(\d+);?/) {
|
|
450
|
+
begin
|
|
451
|
+
[$1.to_i].pack("U*")
|
|
452
|
+
rescue
|
|
453
|
+
""
|
|
454
|
+
end
|
|
455
|
+
}
|
|
456
|
+
.gsub(/&([a-z][a-z0-9]+);?/i) {
|
|
457
|
+
NAMED_CHARACTER_REFERENCES[$1.downcase] || ""
|
|
458
|
+
}
|
|
459
|
+
end
|
|
460
|
+
|
|
424
461
|
# @api private
|
|
425
462
|
def __build_attributes__(attributes, buffer:)
|
|
426
463
|
attributes.each do |k, v|
|
|
@@ -433,10 +470,47 @@ module Phlex
|
|
|
433
470
|
end
|
|
434
471
|
|
|
435
472
|
lower_name = name.downcase
|
|
436
|
-
|
|
473
|
+
normalized_name = lower_name.delete("^a-z")
|
|
474
|
+
|
|
475
|
+
if REF_ATTRIBUTES.include?(normalized_name) || DATA_ATTRIBUTE == normalized_name
|
|
476
|
+
# The text the value will be rendered as, whatever its type, so a
|
|
477
|
+
# URI or a list of tokens is checked like a String.
|
|
478
|
+
reference = case v
|
|
479
|
+
when String then v
|
|
480
|
+
when Symbol then v.name
|
|
481
|
+
when Array then v.compact.join(" ")
|
|
482
|
+
when Set then v.to_a.compact.join(" ")
|
|
483
|
+
when true, Integer, Float, Hash then nil
|
|
484
|
+
else
|
|
485
|
+
if v.respond_to?(:to_phlex_attribute_value)
|
|
486
|
+
v.to_phlex_attribute_value.to_s
|
|
487
|
+
elsif v.respond_to?(:to_str)
|
|
488
|
+
v.to_str
|
|
489
|
+
else
|
|
490
|
+
v.to_s
|
|
491
|
+
end
|
|
492
|
+
end
|
|
493
|
+
|
|
494
|
+
decoded_value = reference && decode_html_character_references(reference)
|
|
495
|
+
|
|
496
|
+
if decoded_value
|
|
497
|
+
decoded_value = decoded_value.downcase
|
|
498
|
+
|
|
499
|
+
if REF_LIST_ATTRIBUTES.include?(normalized_name)
|
|
500
|
+
# The decoder removes references it doesn't know, but a browser keeps
|
|
501
|
+
# them as text, so it could see a `;` the decoder removed. Removing
|
|
502
|
+
# text can't break up an entry's `javascript:`, so the list is unsafe
|
|
503
|
+
# if `javascript:` appears anywhere in it.
|
|
504
|
+
next if decoded_value.tr("^a-z:", "").include?("javascript:")
|
|
505
|
+
elsif decoded_value.tr("^a-z:", "").start_with?("javascript:")
|
|
506
|
+
next
|
|
507
|
+
end
|
|
508
|
+
end
|
|
509
|
+
end
|
|
437
510
|
|
|
438
|
-
# Detect unsafe attribute names. Attribute names are considered unsafe if they
|
|
439
|
-
|
|
511
|
+
# Detect unsafe attribute names. Attribute names are considered unsafe if they look like an event attribute, `on` followed by letters, or include unsafe characters.
|
|
512
|
+
event_name = lower_name.tr("^a-z-", "")
|
|
513
|
+
if (event_name.length > 2 && event_name.start_with?("on") && !event_name.include?("-")) || name.match?(UNSAFE_ATTRIBUTE_NAME_CHARS)
|
|
440
514
|
raise ArgumentError, "Unsafe attribute name detected: #{k}."
|
|
441
515
|
end
|
|
442
516
|
|
data/lib/phlex/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: phlex
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.11.
|
|
4
|
+
version: 1.11.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Joel Drapper
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-11-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: A high-performance view framework optimised for fun.
|
|
14
14
|
email:
|
|
@@ -62,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
62
62
|
- !ruby/object:Gem::Version
|
|
63
63
|
version: '0'
|
|
64
64
|
requirements: []
|
|
65
|
-
rubygems_version: 3.5.
|
|
65
|
+
rubygems_version: 3.5.3
|
|
66
66
|
signing_key:
|
|
67
67
|
specification_version: 4
|
|
68
68
|
summary: A fun framework for building views in Ruby.
|