quixoten-puppetdb-terminus 3.2.2 → 3.2.3
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/puppet/util/puppetdb/char_encoding.rb +35 -52
- data/lib/puppetdb/terminus/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e45da9f15369e2e8dc3a59116c008e4b07be912
|
4
|
+
data.tar.gz: 4a0c080aec986122dc8abd2a4d276e6242cfd140
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94b4278ca6f334d9177a9945f4b8f3fe8c514eca44a78160ac9001584e076fb72f3bee47c2b63536c74cfada4445abf765abe9d469418580555d4e36462c8944
|
7
|
+
data.tar.gz: f7125969eb043f116f6ce808106b0c2267860fda85d7cfc09ca293f2745b584dbd0830fc44680f0a66a8c94357c17c029c31b720ebf5d9ba0db62944703f897a
|
@@ -32,66 +32,48 @@ module CharEncoding
|
|
32
32
|
Utf8ReplacementChar = [ 0xEF, 0xBF, 0xBD ].pack("c*")
|
33
33
|
|
34
34
|
DEFAULT_INVALID_CHAR = "\ufffd"
|
35
|
-
|
36
|
-
# @api private
|
37
|
-
def self.all_indexes_of_char(str, char)
|
38
|
-
(0..str.length).find_all{ |i| str[i] == char}
|
39
|
-
end
|
35
|
+
NOT_INVALID_REGEX = Regexp.new( "[^" + DEFAULT_INVALID_CHAR + "]" )
|
40
36
|
|
41
37
|
# @api private
|
42
38
|
#
|
43
|
-
#
|
39
|
+
# Finds the beginning and ending index of the first block of invalid
|
40
|
+
# characters.
|
44
41
|
#
|
45
|
-
# @
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
# @param index_array an array of sorted integers
|
56
|
-
# @return [Range]
|
57
|
-
def self.collapse_ranges(index_array)
|
58
|
-
ranges = index_array.each.inject([]) do |spans, n|
|
59
|
-
if spans.empty? || spans.last.end != n - 1
|
60
|
-
spans << Range.new(n, n)
|
61
|
-
else
|
62
|
-
drop_last(spans) << Range.new(spans.last.begin,n)
|
63
|
-
end
|
42
|
+
# @param str string to scan for invalid characters
|
43
|
+
# @return Range
|
44
|
+
def self.first_invalid_char_range(str)
|
45
|
+
begin_bad_chars_idx = str.index(DEFAULT_INVALID_CHAR)
|
46
|
+
|
47
|
+
if begin_bad_chars_idx
|
48
|
+
first_good_char = str.index(NOT_INVALID_REGEX, begin_bad_chars_idx)
|
49
|
+
Range.new(begin_bad_chars_idx, (first_good_char || str.length) - 1)
|
50
|
+
else
|
51
|
+
nil
|
64
52
|
end
|
65
53
|
end
|
66
54
|
|
67
55
|
# @api private
|
68
56
|
#
|
69
|
-
# Scans the string
|
70
|
-
# and returns
|
71
|
-
# bad characters. This will give up to 100 characters prior to
|
72
|
-
# bad character and 100 after. It will return fewer if it's at
|
73
|
-
# beginning of a string or if another bad character appears
|
74
|
-
# reaching the 100 characters
|
57
|
+
# Scans the string str with invalid characters found at
|
58
|
+
# bad_char_range and returns a message that give some context around
|
59
|
+
# the bad characters. This will give up to 100 characters prior to
|
60
|
+
# the bad character and 100 after. It will return fewer if it's at
|
61
|
+
# the beginning of a string or if another bad character appears
|
62
|
+
# before reaching the 100 characters
|
75
63
|
#
|
76
64
|
# @param str string coming from to_pson, likely a command to be submitted to PDB
|
77
|
-
# @param
|
78
|
-
# @return
|
79
|
-
def self.error_char_context(str,
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
x = [next_bad_char_begin || str.length, r.end+100, str.length]
|
90
|
-
prefix = str[start_char..r.begin-1]
|
91
|
-
suffix = str[r.end+1..end_char]
|
92
|
-
|
93
|
-
state << "'#{prefix}' followed by #{gap} invalid/undefined bytes then '#{suffix}'"
|
94
|
-
end
|
65
|
+
# @param bad_char_range a range indicating a block of invalid characters
|
66
|
+
# @return String
|
67
|
+
def self.error_char_context(str, bad_char_range)
|
68
|
+
|
69
|
+
gap = bad_char_range.to_a.length
|
70
|
+
|
71
|
+
start_char = [0, bad_char_range.begin-100].max
|
72
|
+
end_char = [str.index(DEFAULT_INVALID_CHAR, bad_char_range.end+1) || str.length, bad_char_range.end+100].min
|
73
|
+
prefix = str[start_char..bad_char_range.begin-1]
|
74
|
+
suffix = str[bad_char_range.end+1..end_char-1]
|
75
|
+
|
76
|
+
"'#{prefix}' followed by #{gap} invalid/undefined bytes then '#{suffix}'"
|
95
77
|
end
|
96
78
|
|
97
79
|
# @api private
|
@@ -104,13 +86,14 @@ module CharEncoding
|
|
104
86
|
# @param error_context_str information about where this string came from for use in error messages
|
105
87
|
# @return String
|
106
88
|
def self.warn_if_invalid_chars(str, error_context_str)
|
107
|
-
|
108
|
-
if
|
89
|
+
|
90
|
+
if str.index(DEFAULT_INVALID_CHAR).nil?
|
109
91
|
str
|
110
92
|
else
|
111
93
|
Puppet.warning "#{error_context_str} ignoring invalid UTF-8 byte sequences in data to be sent to PuppetDB, see debug logging for more info"
|
94
|
+
|
112
95
|
if Puppet.settings[:log_level] == "debug"
|
113
|
-
Puppet.debug error_context_str + "\n" + error_char_context(str,
|
96
|
+
Puppet.debug error_context_str + "\n" + error_char_context(str, first_invalid_char_range(str))
|
114
97
|
end
|
115
98
|
|
116
99
|
str
|