sparkql 1.3.3 → 1.3.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1fb6060ec97e59958c12e0ed3338540afa180bf28eab0224af3ffef568dbf469
4
- data.tar.gz: 982d3956830686faeb210e6abf52125d18d4d68fa0d231b00a251a4876e1bd14
3
+ metadata.gz: 995514ae40305cedb2116dafc6c98b8efb534ae3d2f31c9d48e86421e3f5c10c
4
+ data.tar.gz: 6162d29fb4520941edb2b53742d966fdf373418b2745f6fd1d8c1fa79432b896
5
5
  SHA512:
6
- metadata.gz: 6754d10ca449bbd3467127a8470bb4233dd00b5162984ca636bcd93aff41743b25ace78fdd30ba77cbb6a79bef55d36118f67f2102b676ca9184db04c2437c01
7
- data.tar.gz: d337d7169ceb202c6f4d8a066196c472404cccf5e1b6f0fc13bf07a4fba62fa6d135c04bfc017544c73fb84ca1834f5d06c78bbf5ee2848ac16b06372b09b711
6
+ metadata.gz: c39c06894d6a7b298d4fafb3c578e6d203543c77c68ad0cf8acb9ec943c00c656e38529a7e6b2afe4cc3177b5a59b078c7ce4c193a08dea0f575bd62ee0495d7
7
+ data.tar.gz: fbbba23b099146c85f3c15fb82ea3bbc93fe989b156752a80137a2212b2ed64f4cf50ecb99bf06b59914f1e1f8996a65155c9cde11c025702e6b8504b083cc93
data/CHANGELOG.md CHANGED
@@ -1,3 +1,5 @@
1
+ v1.3.4, 20265-01-20
2
+ * [BUGFIX] Validate limit for days and weekdays
1
3
 
2
4
  v1.3.3, 2025-08-12
3
5
  -------------------
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.3
1
+ 1.3.4
@@ -21,6 +21,7 @@ module Sparkql
21
21
  VALID_REGEX_FLAGS = ['', 'i'].freeze
22
22
  MIN_DATE_TIME = Time.new(1970, 1, 1, 0, 0, 0, '+00:00').iso8601
23
23
  MAX_DATE_TIME = Time.new(9999, 12, 31, 23, 59, 59, '+00:00').iso8601
24
+ MAX_DAYS = (365 * 1000).freeze # 1000 years ought to cover most cases
24
25
  VALID_CAST_TYPES = %i[field character decimal integer].freeze
25
26
 
26
27
  SUPPORTED_FUNCTIONS = {
@@ -43,16 +44,16 @@ module Sparkql
43
44
  regex: {
44
45
  args: [:character],
45
46
  opt_args: [{
46
- type: :character,
47
- default: ''
48
- }],
47
+ type: :character,
48
+ default: ''
49
+ }],
49
50
  return_type: :character
50
51
  },
51
52
  substring: {
52
53
  args: [%i[field character], :integer],
53
54
  opt_args: [{
54
- type: :integer
55
- }],
55
+ type: :integer
56
+ }],
56
57
  resolve_for_type: true,
57
58
  return_type: :character
58
59
  },
@@ -526,6 +527,15 @@ module Sparkql
526
527
 
527
528
  # Offset the current timestamp by a number of days
528
529
  def days(number_of_days)
530
+ if number_of_days.abs > MAX_DAYS
531
+ @errors << Sparkql::ParserError.new(token: number_of_days,
532
+ message: "Function call 'days' max offset #{MAX_DAYS} days",
533
+ status: :fatal,
534
+ syntax: false,
535
+ constraint: true)
536
+ return
537
+ end
538
+
529
539
  # date calculated as the offset from midnight tommorrow. Zero will provide values for all times
530
540
  # today.
531
541
  d = current_date + number_of_days
@@ -536,6 +546,15 @@ module Sparkql
536
546
  end
537
547
 
538
548
  def weekdays(number_of_days)
549
+ if number_of_days.abs > MAX_DAYS
550
+ @errors << Sparkql::ParserError.new(token: number_of_days,
551
+ message: "Function call 'weekdays' max offset #{MAX_DAYS} days",
552
+ status: :fatal,
553
+ syntax: false,
554
+ constraint: true)
555
+ return
556
+ end
557
+
539
558
  today = current_date
540
559
  weekend_start = today.saturday? || today.sunday?
541
560
  direction = number_of_days.positive? ? 1 : -1
@@ -445,6 +445,24 @@ class FunctionResolverTest < Test::Unit::TestCase
445
445
  end
446
446
  end
447
447
 
448
+ test 'days - exceed max' do
449
+ f = FunctionResolver.new('days',
450
+ [{ type: :integer, value: 365_001 }],
451
+ current_timestamp: EXAMPLE_DATE)
452
+ f.validate
453
+ assert !f.errors?
454
+ assert_nil f.call
455
+ assert f.errors?, "function 'days' limit 365000"
456
+
457
+ f = FunctionResolver.new('days',
458
+ [{ type: :integer, value: -365_001 }],
459
+ current_timestamp: EXAMPLE_DATE)
460
+ f.validate
461
+ assert !f.errors?
462
+ assert_nil f.call
463
+ assert f.errors?, "function 'days' limit 365000"
464
+ end
465
+
448
466
  test 'weekdays()' do
449
467
  friday = Date.new(2012, 10, 19)
450
468
  saturday = Date.new(2012, 10, 20)
@@ -514,6 +532,24 @@ class FunctionResolverTest < Test::Unit::TestCase
514
532
  end
515
533
  end
516
534
 
535
+ test 'weekdays - exceed max' do
536
+ f = FunctionResolver.new('weekdays',
537
+ [{ type: :integer, value: 365_001 }],
538
+ current_timestamp: EXAMPLE_DATE)
539
+ f.validate
540
+ assert !f.errors?
541
+ assert_nil f.call
542
+ assert f.errors?, "function 'weekdays' limit 365000"
543
+
544
+ f = FunctionResolver.new('weekdays',
545
+ [{ type: :integer, value: -365_001 }],
546
+ current_timestamp: EXAMPLE_DATE)
547
+ f.validate
548
+ assert !f.errors?
549
+ assert_nil f.call
550
+ assert f.errors?, "function 'weekdays' limit 365000"
551
+ end
552
+
517
553
  test 'months()' do
518
554
  f = FunctionResolver.new('months',
519
555
  [{ type: :integer, value: 3 }],
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sparkql
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3
4
+ version: 1.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wade McEwen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-08-19 00:00:00.000000000 Z
11
+ date: 2026-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: georuby