katalyst-tables 3.15.0 → 3.15.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/CHANGELOG.md +14 -0
- data/lib/katalyst/tables/collection/type/boolean.rb +1 -1
- data/lib/katalyst/tables/collection/type/enum.rb +22 -1
- data/lib/katalyst/tables/collection/type/float.rb +9 -0
- data/lib/katalyst/tables/collection/type/helpers/multiple.rb +2 -0
- data/lib/katalyst/tables/collection/type/integer.rb +11 -1
- data/lib/katalyst/tables/collection/type/value.rb +34 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6d3667ae86fae4850ddda5e73db980cf7ae5250514ea43820f9c45f7fdfe54d0
|
|
4
|
+
data.tar.gz: 8223000b7268a6f87ad74b82225eab728c3d7cf1e52871cd28f062fc6976288b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 97b5d21f99d9178f64c9918467d423a64134bc23e195ce515ddf6346f670565b95c8540edde79e75fbd05946e6cb75646291a553f28806abee4b66eed65fdec5
|
|
7
|
+
data.tar.gz: 2d09f88cfbb4e10b28dab7b8a16123c2a6304030ff32d55165c5c0f41a1b683b6a019fe3ff97e92e74a7936422dbb5119a1620a2ccbe5d184749b67824e5aa26
|
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
## [3.15.0]
|
|
2
2
|
|
|
3
3
|
* Date filters on datetime columns now match whole days in `Time.zone`, including the last day of a range (#169)
|
|
4
|
+
* Collection inputs containing NUL bytes are treated as invalid and match nothing, instead of raising database errors (#171)
|
|
5
|
+
* Applies to all collection types; values in `multiple` attributes are ignored individually
|
|
6
|
+
* Invalid input now matches nothing for attributes with a custom `scope:`, instead of calling the scope with `nil`
|
|
7
|
+
* Integer filters accept bigint values and leave range checks to the database column, instead of raising `ActiveModel::RangeError` for values beyond 4 bytes
|
|
8
|
+
* Out of range values match nothing, out of range upper bounds are unbounded, and out of range `multiple` values are ignored
|
|
9
|
+
* Values longer than 16 digits are no longer truncated when cast
|
|
10
|
+
* Float filters treat `NaN` as invalid input and match nothing
|
|
11
|
+
* Blank and invalid values in `multiple` integer, float, boolean and enum filters are ignored, instead of also matching rows where the column is `NULL`
|
|
12
|
+
* e.g. the hidden blank value submitted by Rails multiple selects
|
|
13
|
+
* Only blank values (e.g. `[""]`, or `category:[]` in a query) do not filter, and are not reported as filters
|
|
14
|
+
* Enum filters match nothing for unknown values, instead of matching rows where the column is `NULL`
|
|
15
|
+
* Labels and database values are both accepted, as in Active Record
|
|
16
|
+
* Unknown values alongside known values are ignored
|
|
17
|
+
* Attributes with a custom `scope:`, or on columns without a Rails enum, are unchanged
|
|
4
18
|
|
|
5
19
|
## [3.14.0]
|
|
6
20
|
|
|
@@ -39,8 +39,29 @@ module Katalyst
|
|
|
39
39
|
|
|
40
40
|
private
|
|
41
41
|
|
|
42
|
+
# Blank values are removed, as for other multiple value types.
|
|
42
43
|
def cast_value(value)
|
|
43
|
-
value.to_s
|
|
44
|
+
value.to_s.presence
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Active Record filters unknown enum values on IS NULL. Unknown values
|
|
48
|
+
# can't match any row, so remove them, and match nothing if none remain.
|
|
49
|
+
def apply_filter(scope, model, attribute, value)
|
|
50
|
+
mapping = model.defined_enums[attribute.name.split(".").last]
|
|
51
|
+
|
|
52
|
+
# not a Rails enum, leave it to the database
|
|
53
|
+
return super if mapping.nil?
|
|
54
|
+
|
|
55
|
+
known = known_values(mapping, Array(value))
|
|
56
|
+
|
|
57
|
+
known.any? ? super(scope, model, attribute, known) : scope.none
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Accepts labels and database values, matching Active Record.
|
|
61
|
+
def known_values(mapping, values)
|
|
62
|
+
database_values = mapping.values.map(&:to_s)
|
|
63
|
+
|
|
64
|
+
values.select { |v| mapping.key?(v) || database_values.include?(v) }
|
|
44
65
|
end
|
|
45
66
|
end
|
|
46
67
|
end
|
|
@@ -14,6 +14,15 @@ module Katalyst
|
|
|
14
14
|
def initialize(**)
|
|
15
15
|
super(**, delegate: ActiveModel::Type::Float)
|
|
16
16
|
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
# ActiveModel accepts "NaN", but NaN is not equal to anything, so
|
|
21
|
+
# treat it as invalid input.
|
|
22
|
+
def cast_value(value)
|
|
23
|
+
result = super
|
|
24
|
+
result unless result.is_a?(::Float) && result.nan?
|
|
25
|
+
end
|
|
17
26
|
end
|
|
18
27
|
end
|
|
19
28
|
end
|
|
@@ -12,7 +12,17 @@ module Katalyst
|
|
|
12
12
|
define_range_patterns(/-?\d+/)
|
|
13
13
|
|
|
14
14
|
def initialize(**)
|
|
15
|
-
super(**, delegate:
|
|
15
|
+
super(**, delegate: Unbounded)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Integer values are checked against the column's range by Active
|
|
19
|
+
# Record when filtering, which matches nothing for out of range values.
|
|
20
|
+
# BigInteger skips ActiveModel's own 4 byte range check, and limit: 8
|
|
21
|
+
# avoids truncating bigint values when casting from strings.
|
|
22
|
+
class Unbounded < ActiveModel::Type::BigInteger
|
|
23
|
+
def initialize(**)
|
|
24
|
+
super(limit: 8, **)
|
|
25
|
+
end
|
|
16
26
|
end
|
|
17
27
|
end
|
|
18
28
|
end
|
|
@@ -24,7 +24,7 @@ module Katalyst
|
|
|
24
24
|
return false unless filterable?
|
|
25
25
|
|
|
26
26
|
if attribute.came_from_user?
|
|
27
|
-
attribute.value_before_type_cast
|
|
27
|
+
!blank_input?(attribute.value_before_type_cast)
|
|
28
28
|
else
|
|
29
29
|
value.present?
|
|
30
30
|
end
|
|
@@ -33,6 +33,11 @@ module Katalyst
|
|
|
33
33
|
def filter(scope, attribute, value: filter_value(attribute))
|
|
34
34
|
return scope unless filter?(attribute, value)
|
|
35
35
|
|
|
36
|
+
value = without_null_bytes(value)
|
|
37
|
+
|
|
38
|
+
# user input was supplied but it can't match anything
|
|
39
|
+
return scope.none if value.nil?
|
|
40
|
+
|
|
36
41
|
if self.scope.present?
|
|
37
42
|
scope.public_send(self.scope, value)
|
|
38
43
|
elsif attribute.name.include?(".")
|
|
@@ -88,6 +93,34 @@ module Katalyst
|
|
|
88
93
|
Tables::Suggestions::DatabaseValue.new(name: attribute.name, type: attribute.type, value:)
|
|
89
94
|
end
|
|
90
95
|
|
|
96
|
+
# Strings containing NUL bytes can't be sent to the database: Postgres
|
|
97
|
+
# raises ArgumentError when quoting and SQLite truncates the literal.
|
|
98
|
+
# No row can match them, so they are removed before filtering.
|
|
99
|
+
def without_null_bytes(value)
|
|
100
|
+
case value
|
|
101
|
+
when ::String
|
|
102
|
+
value unless value.include?("\0")
|
|
103
|
+
when ::Array
|
|
104
|
+
kept = value.reject { |v| v.is_a?(::String) && v.include?("\0") }
|
|
105
|
+
kept unless kept.empty? && value.any?
|
|
106
|
+
else
|
|
107
|
+
value
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# Blank input means nothing was chosen, e.g. the hidden blank value that
|
|
112
|
+
# Rails multiple selects submit. False is input for boolean filters.
|
|
113
|
+
def blank_input?(value)
|
|
114
|
+
case value
|
|
115
|
+
when ::Array
|
|
116
|
+
value.all? { |v| blank_input?(v) }
|
|
117
|
+
when ::String
|
|
118
|
+
value.blank?
|
|
119
|
+
else
|
|
120
|
+
value.nil?
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
91
124
|
def filter_value(attribute)
|
|
92
125
|
attribute.value
|
|
93
126
|
end
|