stduritemplate 2.0.11 → 2.0.13
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/stduritemplate.rb +52 -3
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f6350d591908f7cd193fd7db8098268534a979bdd3bb4b4e629baf743663428e
|
|
4
|
+
data.tar.gz: c1a5db3125d5b4ead01eb2afa7bc692f3e5a7db151fbbf05f2dd847e27efb056
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 40be665502e60d5e55ba6ee9a5a8dff5a2c5ac04e2be2771ec76e17bf4fbf4dd5531270f4b4a98c6c51b5668b962b87205bf6da17376f598545877917359decb
|
|
7
|
+
data.tar.gz: 2a14f0acc8067c3386aec291607eb2e2c35974b88afb89e862ba3c71474ba8a8ea5a0bfcd78ccc321ab99b3485110bf868fdb4511b58548998d16dd12ede1c79
|
data/lib/stduritemplate.rb
CHANGED
|
@@ -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,18 +106,23 @@ 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 = ''
|
|
99
115
|
composite = false
|
|
100
116
|
max_char_buffer = nil
|
|
117
|
+
else
|
|
118
|
+
result << character
|
|
101
119
|
end
|
|
102
120
|
else
|
|
103
121
|
if token
|
|
104
122
|
if operator.nil?
|
|
105
123
|
operator = get_operator(character, token, i)
|
|
106
124
|
elsif max_char_buffer
|
|
107
|
-
if character
|
|
125
|
+
if character >= '0' && character <= '9'
|
|
108
126
|
max_char_buffer << character
|
|
109
127
|
else
|
|
110
128
|
raise ArgumentError, "Illegal character identified in the token at col:#{i}"
|
|
@@ -120,7 +138,11 @@ module StdUriTemplate
|
|
|
120
138
|
end
|
|
121
139
|
end
|
|
122
140
|
else
|
|
123
|
-
|
|
141
|
+
if character.ord > 0x7F
|
|
142
|
+
character.encode('UTF-8').bytes.each { |b| result << sprintf("%%%02X", b) }
|
|
143
|
+
else
|
|
144
|
+
result << character
|
|
145
|
+
end
|
|
124
146
|
end
|
|
125
147
|
end
|
|
126
148
|
end
|
|
@@ -320,8 +342,35 @@ module StdUriTemplate
|
|
|
320
342
|
end
|
|
321
343
|
end
|
|
322
344
|
|
|
345
|
+
def self.hex_digit?(c)
|
|
346
|
+
(c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
def self.check_varname(token, col)
|
|
350
|
+
if token.start_with?('.') || token.end_with?('.')
|
|
351
|
+
raise ArgumentError, "Variable name cannot start or end with a dot at col:#{col}"
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
if token.include?('..')
|
|
355
|
+
raise ArgumentError, "Variable name cannot contain consecutive dots at col:#{col}"
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
i = 0
|
|
359
|
+
while i < token.length
|
|
360
|
+
if token[i] == '%'
|
|
361
|
+
if i + 2 >= token.length || !hex_digit?(token[i + 1]) || !hex_digit?(token[i + 2])
|
|
362
|
+
raise ArgumentError, "Invalid percent encoding in variable name at col:#{col}"
|
|
363
|
+
end
|
|
364
|
+
i += 3
|
|
365
|
+
else
|
|
366
|
+
i += 1
|
|
367
|
+
end
|
|
368
|
+
end
|
|
369
|
+
end
|
|
370
|
+
|
|
323
371
|
def self.expand_token(operator, token, composite, max_char, first_token, substitutions, result, col)
|
|
324
372
|
raise ArgumentError, "Found an empty token at col:#{col}" if token.empty?
|
|
373
|
+
check_varname(token, col)
|
|
325
374
|
|
|
326
375
|
value = substitutions[token]
|
|
327
376
|
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.
|
|
4
|
+
version: 2.0.13
|
|
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-
|
|
11
|
+
date: 2026-10-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: std-uritemplate implementation for Ruby
|
|
14
14
|
email: andrea.peruffo1982@gmail.com
|