stduritemplate 2.0.11 → 2.0.12

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/stduritemplate.rb +50 -3
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6139a327604fe23ea2b1d0d6462a04bb3e39b92dfd6eecaf999478a35c0a14ed
4
- data.tar.gz: 318bd34e6a738fa37e9e755f62bae935c38dc4bf787c804ca278d8f3df833db7
3
+ metadata.gz: 934938b208bf9f45f42db597a4f30ce750c5437ebd7f2e87eb6675437325d2a0
4
+ data.tar.gz: 6dcde2182655ea5036301dd9645e81d42150f185db0fa62c8442f5df900c05b7
5
5
  SHA512:
6
- metadata.gz: 6ebad292aec88e02b8c717e727771fafe4b6872460acea41552d29c91e09e1bee66437fd4857fa6649d0452692b316a085f04be19331d83ad8cbc97f9eb0719e
7
- data.tar.gz: fa77853017cd993d6b24b3be8a7642ebafaa67256da994e6109df300ddc5971bd30b8581ec3016ceb04ed0de8769246248baf9abd842948d5bd43fa2bfd7ab59
6
+ metadata.gz: f3c5e97ca93552bd88355caa49ac7278de60eb9a3e9722e27a493352686030c00b35d39967f4dfb6825a1b18d9c6f2f0a6a7ff4783204234f7de6609efcfa7a5
7
+ data.tar.gz: bc06e9a9e4da9844e72c0e410b74a1250565ec7688efcccff3d56418211e33cdacd70e97e9565df352cf762dd50e3899ff61b3a21f7599fb2f3034f4b2343f52
@@ -37,10 +37,20 @@ module StdUriTemplate
37
37
  -1
38
38
  else
39
39
  begin
40
- Integer(value)
40
+ parsed = Integer(value)
41
41
  rescue ArgumentError
42
42
  raise ArgumentError, "Cannot parse max chars at col:#{col}"
43
43
  end
44
+
45
+ if value.start_with?('0')
46
+ raise ArgumentError, "Leading zeros are not allowed in max chars at col:#{col}"
47
+ end
48
+
49
+ if parsed < 1 || parsed > 9999
50
+ raise ArgumentError, "Max chars must be between 1 and 9999 at col:#{col}"
51
+ end
52
+
53
+ parsed
44
54
  end
45
55
  end
46
56
 
@@ -82,6 +92,9 @@ module StdUriTemplate
82
92
  first_token = true
83
93
  when '}'
84
94
  if token
95
+ if !max_char_buffer.nil? && max_char_buffer.empty?
96
+ raise ArgumentError, "Empty prefix after colon at col:#{i}"
97
+ end
85
98
  expanded = expand_token(operator, token, composite, get_max_char(max_char_buffer, i), first_token, substitutions, result, i)
86
99
  first_token = false if expanded && first_token
87
100
  token = nil
@@ -93,6 +106,9 @@ module StdUriTemplate
93
106
  end
94
107
  when ','
95
108
  if token
109
+ if !max_char_buffer.nil? && max_char_buffer.empty?
110
+ raise ArgumentError, "Empty prefix after colon at col:#{i}"
111
+ end
96
112
  expanded = expand_token(operator, token, composite, get_max_char(max_char_buffer, i), first_token, substitutions, result, i)
97
113
  first_token = false if expanded && first_token
98
114
  token = ''
@@ -104,7 +120,7 @@ module StdUriTemplate
104
120
  if operator.nil?
105
121
  operator = get_operator(character, token, i)
106
122
  elsif max_char_buffer
107
- if character =~ /\d/
123
+ if character >= '0' && character <= '9'
108
124
  max_char_buffer << character
109
125
  else
110
126
  raise ArgumentError, "Illegal character identified in the token at col:#{i}"
@@ -120,7 +136,11 @@ module StdUriTemplate
120
136
  end
121
137
  end
122
138
  else
123
- result << character
139
+ if character.ord > 0x7F
140
+ character.encode('UTF-8').bytes.each { |b| result << sprintf("%%%02X", b) }
141
+ else
142
+ result << character
143
+ end
124
144
  end
125
145
  end
126
146
  end
@@ -320,8 +340,35 @@ module StdUriTemplate
320
340
  end
321
341
  end
322
342
 
343
+ def self.hex_digit?(c)
344
+ (c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')
345
+ end
346
+
347
+ def self.check_varname(token, col)
348
+ if token.start_with?('.') || token.end_with?('.')
349
+ raise ArgumentError, "Variable name cannot start or end with a dot at col:#{col}"
350
+ end
351
+
352
+ if token.include?('..')
353
+ raise ArgumentError, "Variable name cannot contain consecutive dots at col:#{col}"
354
+ end
355
+
356
+ i = 0
357
+ while i < token.length
358
+ if token[i] == '%'
359
+ if i + 2 >= token.length || !hex_digit?(token[i + 1]) || !hex_digit?(token[i + 2])
360
+ raise ArgumentError, "Invalid percent encoding in variable name at col:#{col}"
361
+ end
362
+ i += 3
363
+ else
364
+ i += 1
365
+ end
366
+ end
367
+ end
368
+
323
369
  def self.expand_token(operator, token, composite, max_char, first_token, substitutions, result, col)
324
370
  raise ArgumentError, "Found an empty token at col:#{col}" if token.empty?
371
+ check_varname(token, col)
325
372
 
326
373
  value = substitutions[token]
327
374
  subst_type = get_substitution_type(value, col)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stduritemplate
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.11
4
+ version: 2.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrea Peruffo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-07-06 00:00:00.000000000 Z
11
+ date: 2026-07-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: std-uritemplate implementation for Ruby
14
14
  email: andrea.peruffo1982@gmail.com