fractalpenguin-googlesso 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/FractalPenguinGoogleSSO.rb +1 -1
- data/lib/xmlcanonicalizer.rb +359 -360
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5dbd427592e1193c56d2a030f0f4b0e6049db14
|
4
|
+
data.tar.gz: ab26eac4d783f78db530b0f515fc79e12b6dd9bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4d30aae1a4daa5dc81b023c7a96052177aff58e7373faa9c85ee02aaef0c4a22df75b1c998e57f65b161b48549b65d51f243843ca8dc75a165e1cacdea97b5a
|
7
|
+
data.tar.gz: 07345ca2b3b214aee4676cd63ed42b810c234a650d578307eafdb6c1753f175683527628e9a197f7d363d8e6efb63489d3733b21882ca741f32d5ffd16763007
|
data/lib/xmlcanonicalizer.rb
CHANGED
@@ -3,393 +3,392 @@ require "base64"
|
|
3
3
|
|
4
4
|
include REXML
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
writer << STOP.sub(/\\/u, '')
|
15
|
-
end
|
6
|
+
class REXML::Instruction
|
7
|
+
def write(writer, indent=-1, transitive=false, ie_hack=false)
|
8
|
+
indent(writer, indent)
|
9
|
+
writer << START.sub(/\\/u, '')
|
10
|
+
writer << @target
|
11
|
+
writer << ' '
|
12
|
+
writer << @content if @content != nil
|
13
|
+
writer << STOP.sub(/\\/u, '')
|
16
14
|
end
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
if (self.prefix() == nil)
|
30
|
-
return -1
|
31
|
-
elsif (a2.prefix() == nil)
|
32
|
-
return 1
|
33
|
-
end
|
34
|
-
ret = self.namespace()<=>a2.namespace()
|
35
|
-
if (ret == 0)
|
36
|
-
ret = self.prefix()<=>a2.prefix()
|
37
|
-
end
|
38
|
-
return ret
|
15
|
+
end
|
16
|
+
|
17
|
+
class REXML::Attribute
|
18
|
+
def <=>(a2)
|
19
|
+
if (self === a2)
|
20
|
+
return 0
|
21
|
+
elsif (self == nil)
|
22
|
+
return -1
|
23
|
+
elsif (a2 == nil)
|
24
|
+
return 1
|
25
|
+
elsif (self.prefix() == a2.prefix())
|
26
|
+
return self.name()<=>a2.name()
|
39
27
|
end
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
if (self.namespace(prefix) == nil)
|
45
|
-
return (self.parent().search_namespace(prefix)) if (self.parent() != nil)
|
46
|
-
else
|
47
|
-
return self.namespace(prefix)
|
48
|
-
end
|
28
|
+
if (self.prefix() == nil)
|
29
|
+
return -1
|
30
|
+
elsif (a2.prefix() == nil)
|
31
|
+
return 1
|
49
32
|
end
|
50
|
-
|
51
|
-
|
33
|
+
ret = self.namespace()<=>a2.namespace()
|
34
|
+
if (ret == 0)
|
35
|
+
ret = self.prefix()<=>a2.prefix()
|
52
36
|
end
|
53
|
-
|
54
|
-
|
37
|
+
return ret
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class REXML::Element
|
42
|
+
def search_namespace(prefix)
|
43
|
+
if (self.namespace(prefix) == nil)
|
44
|
+
return (self.parent().search_namespace(prefix)) if (self.parent() != nil)
|
45
|
+
else
|
46
|
+
return self.namespace(prefix)
|
55
47
|
end
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
48
|
+
end
|
49
|
+
def rendered=(rendered)
|
50
|
+
@rendered = rendered
|
51
|
+
end
|
52
|
+
def rendered?()
|
53
|
+
return @rendered
|
54
|
+
end
|
55
|
+
def node_namespaces()
|
56
|
+
ns = Array.new()
|
57
|
+
ns.push(self.prefix())
|
58
|
+
self.attributes().each_attribute{|a|
|
59
|
+
if (a.prefix() == "xmlns" or (a.prefix() == "" && a.local_name() == "xmlns"))
|
60
|
+
ns.push("xmlns")
|
61
|
+
end
|
62
|
+
}
|
63
|
+
self.prefixes().each { |prefix| ns.push(prefix) }
|
64
|
+
ns
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
class NamespaceNode
|
69
|
+
attr_reader :prefix, :uri
|
70
|
+
def initialize(prefix, uri)
|
71
|
+
@prefix = prefix
|
72
|
+
@uri = uri
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class XmlCanonicalizer
|
77
|
+
attr_accessor :prefix_list, :logger
|
78
|
+
|
79
|
+
BEFORE_DOC_ELEMENT = 0
|
80
|
+
INSIDE_DOC_ELEMENT = 1
|
81
|
+
AFTER_DOC_ELEMENT = 2
|
82
|
+
|
83
|
+
NODE_TYPE_ATTRIBUTE = 3
|
84
|
+
NODE_TYPE_WHITESPACE = 4
|
85
|
+
NODE_TYPE_COMMENT = 5
|
86
|
+
NODE_TYPE_PI = 6
|
87
|
+
NODE_TYPE_TEXT = 7
|
88
|
+
|
89
|
+
|
90
|
+
def initialize(with_comments, excl_c14n)
|
91
|
+
@with_comments = with_comments
|
92
|
+
@exclusive = excl_c14n
|
93
|
+
@res = ""
|
94
|
+
@state = BEFORE_DOC_ELEMENT
|
95
|
+
@xnl = Array.new()
|
96
|
+
@prevVisibleNamespacesStart = 0
|
97
|
+
@prevVisibleNamespacesEnd = 0
|
98
|
+
@visibleNamespaces = Array.new()
|
99
|
+
@inclusive_namespaces = Array.new()
|
100
|
+
@prefix_list = nil
|
101
|
+
@rendered_prefixes = Array.new()
|
102
|
+
@logger = nil#Logger.new("xmlcanonicalizer.log")
|
103
|
+
#@logger.level = Logger::DEBUG
|
104
|
+
end
|
105
|
+
|
106
|
+
def add_inclusive_namespaces(prefix_list, element, visible_namespaces)
|
107
|
+
namespaces = element.attributes()
|
108
|
+
namespaces.each_attribute{|ns|
|
109
|
+
if (ns.prefix=="xmlns")
|
110
|
+
if (prefix_list.include?(ns.local_name()))
|
111
|
+
visible_namespaces.push(NamespaceNode.new("xmlns:"+ns.local_name(), ns.value()))
|
62
112
|
end
|
113
|
+
end
|
114
|
+
}
|
115
|
+
parent = element.parent()
|
116
|
+
add_inclusive_namespaces(prefix_list, parent, visible_namespaces) if (parent)
|
117
|
+
visible_namespaces
|
118
|
+
end
|
119
|
+
|
120
|
+
def canonicalize(document)
|
121
|
+
write_document_node(document)
|
122
|
+
@logger.debug("\nCanonicalized result\n" + @res.to_s()) if @logger
|
123
|
+
@res
|
124
|
+
end
|
125
|
+
|
126
|
+
def canonicalize_element(element, logging = true)
|
127
|
+
@logger.debug("Canonicalize element:\n" + element.to_s()) if @logger
|
128
|
+
@inclusive_namespaces = add_inclusive_namespaces(@prefix_list, element, @inclusive_namespaces) if (@prefix_list)
|
129
|
+
@preserve_document = element.document()
|
130
|
+
tmp_parent = element.parent()
|
131
|
+
body_string = remove_whitespace(element.to_s().gsub("\n","").gsub("\t","").gsub("\r",""))
|
132
|
+
document = Document.new(body_string)
|
133
|
+
tmp_parent.delete_element(element)
|
134
|
+
element = tmp_parent.add_element(document.root())
|
135
|
+
@preserve_element = element
|
136
|
+
document = Document.new(element.to_s())
|
137
|
+
ns = element.namespace(element.prefix())
|
138
|
+
document.root().add_namespace(element.prefix(), ns)
|
139
|
+
write_document_node(document)
|
140
|
+
@logger.debug("Canonicalized result:\n" + @res.to_s()) if @logger
|
141
|
+
@res
|
142
|
+
end
|
143
|
+
|
144
|
+
def write_document_node(document)
|
145
|
+
@state = BEFORE_DOC_ELEMENT
|
146
|
+
if (document.class().to_s() == "REXML::Element")
|
147
|
+
write_node(document)
|
148
|
+
else
|
149
|
+
document.each_child{|child|
|
150
|
+
write_node(child)
|
63
151
|
}
|
64
|
-
self.prefixes().each { |prefix| ns.push(prefix) }
|
65
|
-
ns
|
66
152
|
end
|
153
|
+
@res
|
67
154
|
end
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
155
|
+
|
156
|
+
def write_node(node)
|
157
|
+
visible = is_node_visible(node)
|
158
|
+
if ((node.node_type() == :text) && white_text?(node.value()))
|
159
|
+
res = node.value()
|
160
|
+
res.gsub("\r\n","\n")
|
161
|
+
#res = res.delete(" ").delete("\t")
|
162
|
+
res.delete("\r")
|
163
|
+
@res = @res + res
|
164
|
+
#write_text_node(node,visible) if (@state == INSIDE_DOC_ELEMENT)
|
165
|
+
return
|
74
166
|
end
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
attr_accessor :prefix_list, :logger
|
79
|
-
|
80
|
-
BEFORE_DOC_ELEMENT = 0
|
81
|
-
INSIDE_DOC_ELEMENT = 1
|
82
|
-
AFTER_DOC_ELEMENT = 2
|
83
|
-
|
84
|
-
NODE_TYPE_ATTRIBUTE = 3
|
85
|
-
NODE_TYPE_WHITESPACE = 4
|
86
|
-
NODE_TYPE_COMMENT = 5
|
87
|
-
NODE_TYPE_PI = 6
|
88
|
-
NODE_TYPE_TEXT = 7
|
89
|
-
|
90
|
-
|
91
|
-
def initialize(with_comments, excl_c14n)
|
92
|
-
@with_comments = with_comments
|
93
|
-
@exclusive = excl_c14n
|
94
|
-
@res = ""
|
95
|
-
@state = BEFORE_DOC_ELEMENT
|
96
|
-
@xnl = Array.new()
|
97
|
-
@prevVisibleNamespacesStart = 0
|
98
|
-
@prevVisibleNamespacesEnd = 0
|
99
|
-
@visibleNamespaces = Array.new()
|
100
|
-
@inclusive_namespaces = Array.new()
|
101
|
-
@prefix_list = nil
|
102
|
-
@rendered_prefixes = Array.new()
|
103
|
-
@logger = nil#Logger.new("xmlcanonicalizer.log")
|
104
|
-
#@logger.level = Logger::DEBUG
|
167
|
+
if (node.node_type() == :text)
|
168
|
+
write_text_node(node, visible)
|
169
|
+
return
|
105
170
|
end
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
namespaces.each_attribute{|ns|
|
110
|
-
if (ns.prefix=="xmlns")
|
111
|
-
if (prefix_list.include?(ns.local_name()))
|
112
|
-
visible_namespaces.push(NamespaceNode.new("xmlns:"+ns.local_name(), ns.value()))
|
113
|
-
end
|
114
|
-
end
|
115
|
-
}
|
116
|
-
parent = element.parent()
|
117
|
-
add_inclusive_namespaces(prefix_list, parent, visible_namespaces) if (parent)
|
118
|
-
visible_namespaces
|
171
|
+
if (node.node_type() == :element)
|
172
|
+
write_element_node(node, visible) if (!node.rendered?())
|
173
|
+
node.rendered=(true)
|
119
174
|
end
|
120
|
-
|
121
|
-
def canonicalize(document)
|
122
|
-
write_document_node(document)
|
123
|
-
@logger.debug("\nCanonicalized result\n" + @res.to_s()) if @logger
|
124
|
-
@res
|
175
|
+
if (node.node_type() == :processing_instruction)
|
125
176
|
end
|
126
|
-
|
127
|
-
def canonicalize_element(element, logging = true)
|
128
|
-
@logger.debug("Canonicalize element:\n" + element.to_s()) if @logger
|
129
|
-
@inclusive_namespaces = add_inclusive_namespaces(@prefix_list, element, @inclusive_namespaces) if (@prefix_list)
|
130
|
-
@preserve_document = element.document()
|
131
|
-
tmp_parent = element.parent()
|
132
|
-
body_string = remove_whitespace(element.to_s().gsub("\n","").gsub("\t","").gsub("\r",""))
|
133
|
-
document = Document.new(body_string)
|
134
|
-
tmp_parent.delete_element(element)
|
135
|
-
element = tmp_parent.add_element(document.root())
|
136
|
-
@preserve_element = element
|
137
|
-
document = Document.new(element.to_s())
|
138
|
-
ns = element.namespace(element.prefix())
|
139
|
-
document.root().add_namespace(element.prefix(), ns)
|
140
|
-
write_document_node(document)
|
141
|
-
@logger.debug("Canonicalized result:\n" + @res.to_s()) if @logger
|
142
|
-
@res
|
177
|
+
if (node.node_type() == :comment)
|
143
178
|
end
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
179
|
+
end
|
180
|
+
|
181
|
+
def write_element_node(node, visible)
|
182
|
+
savedPrevVisibleNamespacesStart = @prevVisibleNamespacesStart
|
183
|
+
savedPrevVisibleNamespacesEnd = @prevVisibleNamespacesEnd
|
184
|
+
savedVisibleNamespacesSize = @visibleNamespaces.size()
|
185
|
+
state = @state
|
186
|
+
state = INSIDE_DOC_ELEMENT if (visible && state == BEFORE_DOC_ELEMENT)
|
187
|
+
@res = @res + "<" + node.expanded_name() if (visible)
|
188
|
+
write_namespace_axis(node, visible)
|
189
|
+
write_attribute_axis(node)
|
190
|
+
@res = @res + ">" if (visible)
|
191
|
+
node.each_child{|child|
|
192
|
+
write_node(child)
|
193
|
+
}
|
194
|
+
@res = @res + "</" +node.expanded_name() + ">" if (visible)
|
195
|
+
@state = AFTER_DOC_ELEMENT if (visible && state == BEFORE_DOC_ELEMENT)
|
196
|
+
@prevVisibleNamespacesStart = savedPrevVisibleNamespacesStart
|
197
|
+
@prevVisibleNamespacesEnd = savedPrevVisibleNamespacesEnd
|
198
|
+
@visibleNamespaces.slice!(savedVisibleNamespacesSize, @visibleNamespaces.size() - savedVisibleNamespacesSize) if (@visibleNamespaces.size() > savedVisibleNamespacesSize)
|
199
|
+
end
|
200
|
+
|
201
|
+
def write_namespace_axis(node, visible)
|
202
|
+
doc = node.document()
|
203
|
+
has_empty_namespace = false
|
204
|
+
list = Array.new()
|
205
|
+
cur = node
|
206
|
+
#while ((cur != nil) && (cur != doc) && (cur.node_type() != :document))
|
207
|
+
namespaces = cur.node_namespaces()
|
208
|
+
namespaces.each{|prefix|
|
209
|
+
next if ((prefix == "xmlns") && (node.namespace(prefix) == ""))
|
210
|
+
namespace = cur.namespace(prefix)
|
211
|
+
next if (is_namespace_node(namespace))
|
212
|
+
next if (node.namespace(prefix) != cur.namespace(prefix))
|
213
|
+
next if (prefix == "xml" && namespace == "http://www.w3.org/XML/1998/namespace")
|
214
|
+
next if (!is_node_visible(cur))
|
215
|
+
rendered = is_namespace_rendered(prefix, namespace)
|
216
|
+
@visibleNamespaces.push(NamespaceNode.new("xmlns:"+prefix,namespace)) if (visible)
|
217
|
+
if ((!rendered) && !list.include?(prefix))
|
218
|
+
list.push(prefix)
|
153
219
|
end
|
154
|
-
|
220
|
+
has_empty_namespace = true if (prefix == nil)
|
221
|
+
}
|
222
|
+
if (visible && !has_empty_namespace && !is_namespace_rendered(nil, nil))
|
223
|
+
@res = @res + ' xmlns=""'
|
155
224
|
end
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
#write_text_node(node,visible) if (@state == INSIDE_DOC_ELEMENT)
|
166
|
-
return
|
167
|
-
end
|
168
|
-
if (node.node_type() == :text)
|
169
|
-
write_text_node(node, visible)
|
170
|
-
return
|
171
|
-
end
|
172
|
-
if (node.node_type() == :element)
|
173
|
-
write_element_node(node, visible) if (!node.rendered?())
|
174
|
-
node.rendered=(true)
|
175
|
-
end
|
176
|
-
if (node.node_type() == :processing_instruction)
|
177
|
-
end
|
178
|
-
if (node.node_type() == :comment)
|
179
|
-
end
|
225
|
+
#TODO: ns of inclusive_list
|
226
|
+
#=begin
|
227
|
+
if ((@prefix_list) && (node.to_s() == node.parent().to_s()))
|
228
|
+
#list.push(node.prefix())
|
229
|
+
@inclusive_namespaces.each{|ns|
|
230
|
+
prefix = ns.prefix().split(":")[1]
|
231
|
+
list.push(prefix) if (!list.include?(prefix) && (!node.attributes.prefixes.include?(prefix)))
|
232
|
+
}
|
233
|
+
@prefix_list = nil
|
180
234
|
end
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
@res = @res + "
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
@
|
196
|
-
@state = AFTER_DOC_ELEMENT if (visible && state == BEFORE_DOC_ELEMENT)
|
197
|
-
@prevVisibleNamespacesStart = savedPrevVisibleNamespacesStart
|
198
|
-
@prevVisibleNamespacesEnd = savedPrevVisibleNamespacesEnd
|
199
|
-
@visibleNamespaces.slice!(savedVisibleNamespacesSize, @visibleNamespaces.size() - savedVisibleNamespacesSize) if (@visibleNamespaces.size() > savedVisibleNamespacesSize)
|
235
|
+
#=end
|
236
|
+
list.sort!()
|
237
|
+
list.insert(0, "xmlns") unless list.delete("xmlns").nil?
|
238
|
+
list.each{|prefix|
|
239
|
+
next if (prefix == "")
|
240
|
+
next if (@rendered_prefixes.include?(prefix))
|
241
|
+
@rendered_prefixes.push(prefix)
|
242
|
+
ns = node.namespace(prefix)
|
243
|
+
ns = @preserve_element.namespace(prefix) if (ns == nil)
|
244
|
+
@res = @res + normalize_string(" " + prefix + '="' + ns + '"', NODE_TYPE_TEXT) if (prefix == "xmlns")
|
245
|
+
@res = @res + normalize_string(" xmlns:" + prefix + '="' + ns + '"', NODE_TYPE_TEXT) if (prefix != nil && prefix != "xmlns")
|
246
|
+
}
|
247
|
+
if (visible)
|
248
|
+
@prevVisibleNamespacesStart = @prevVisibleNamespacesEnd
|
249
|
+
@prevVisibleNamespacesEnd = @visibleNamespaces.size()
|
200
250
|
end
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
end
|
226
|
-
#TODO: ns of inclusive_list
|
227
|
-
#=begin
|
228
|
-
if ((@prefix_list) && (node.to_s() == node.parent().to_s()))
|
229
|
-
#list.push(node.prefix())
|
230
|
-
@inclusive_namespaces.each{|ns|
|
231
|
-
prefix = ns.prefix().split(":")[1]
|
232
|
-
list.push(prefix) if (!list.include?(prefix) && (!node.attributes.prefixes.include?(prefix)))
|
251
|
+
end
|
252
|
+
|
253
|
+
def write_attribute_axis(node)
|
254
|
+
list = Array.new()
|
255
|
+
node.attributes.each_attribute{|attr|
|
256
|
+
list.push(attr) if (!is_namespace_node(attr.value()) && !is_namespace_decl(attr)) # && is_node_visible(
|
257
|
+
}
|
258
|
+
if (!@exclusive && node.parent() != nil && node.parent().parent() != nil)
|
259
|
+
cur = node.parent()
|
260
|
+
while (cur != nil)
|
261
|
+
#next if (cur.attributes() == nil)
|
262
|
+
cur.each_attribute{|attribute|
|
263
|
+
next if (attribute.prefix() != "xml")
|
264
|
+
next if (attribute.prefix().index("xmlns") == 0)
|
265
|
+
next if (node.namespace(attribute.prefix()) == attribute.value())
|
266
|
+
found = true
|
267
|
+
list.each{|n|
|
268
|
+
if (n.prefix() == "xml" && n.value() == attritbute.value())
|
269
|
+
found = true
|
270
|
+
break
|
271
|
+
end
|
272
|
+
}
|
273
|
+
next if (found)
|
274
|
+
list.push(attribute)
|
233
275
|
}
|
234
|
-
@prefix_list = nil
|
235
|
-
end
|
236
|
-
#=end
|
237
|
-
list.sort!()
|
238
|
-
list.insert(0, "xmlns") unless list.delete("xmlns").nil?
|
239
|
-
list.each{|prefix|
|
240
|
-
next if (prefix == "")
|
241
|
-
next if (@rendered_prefixes.include?(prefix))
|
242
|
-
@rendered_prefixes.push(prefix)
|
243
|
-
ns = node.namespace(prefix)
|
244
|
-
ns = @preserve_element.namespace(prefix) if (ns == nil)
|
245
|
-
@res = @res + normalize_string(" " + prefix + '="' + ns + '"', NODE_TYPE_TEXT) if (prefix == "xmlns")
|
246
|
-
@res = @res + normalize_string(" xmlns:" + prefix + '="' + ns + '"', NODE_TYPE_TEXT) if (prefix != nil && prefix != "xmlns")
|
247
|
-
}
|
248
|
-
if (visible)
|
249
|
-
@prevVisibleNamespacesStart = @prevVisibleNamespacesEnd
|
250
|
-
@prevVisibleNamespacesEnd = @visibleNamespaces.size()
|
251
276
|
end
|
252
277
|
end
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
list.push(attr) if (!is_namespace_node(attr.value()) && !is_namespace_decl(attr)) # && is_node_visible(
|
258
|
-
}
|
259
|
-
if (!@exclusive && node.parent() != nil && node.parent().parent() != nil)
|
260
|
-
cur = node.parent()
|
261
|
-
while (cur != nil)
|
262
|
-
#next if (cur.attributes() == nil)
|
263
|
-
cur.each_attribute{|attribute|
|
264
|
-
next if (attribute.prefix() != "xml")
|
265
|
-
next if (attribute.prefix().index("xmlns") == 0)
|
266
|
-
next if (node.namespace(attribute.prefix()) == attribute.value())
|
267
|
-
found = true
|
268
|
-
list.each{|n|
|
269
|
-
if (n.prefix() == "xml" && n.value() == attritbute.value())
|
270
|
-
found = true
|
271
|
-
break
|
272
|
-
end
|
273
|
-
}
|
274
|
-
next if (found)
|
275
|
-
list.push(attribute)
|
276
|
-
}
|
278
|
+
list.each{|attribute|
|
279
|
+
if (attribute != nil)
|
280
|
+
if (attribute.name() != "xmlns")
|
281
|
+
@res = @res + " " + normalize_string(attribute.to_string(), NODE_TYPE_ATTRIBUTE).gsub("'",'"')
|
277
282
|
end
|
283
|
+
# else
|
284
|
+
# @res = @res + " " + normalize_string(attribute.name()+'="'+attribute.to_s()+'"', NODE_TYPE_ATTRIBUTE).gsub("'",'"')
|
285
|
+
#end
|
278
286
|
end
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
return (namespace_uri == "http://www.w3.org/2000/xmlns/")
|
287
|
+
}
|
288
|
+
end
|
289
|
+
|
290
|
+
def is_namespace_node(namespace_uri)
|
291
|
+
return (namespace_uri == "http://www.w3.org/2000/xmlns/")
|
292
|
+
end
|
293
|
+
|
294
|
+
def is_namespace_rendered(prefix, uri)
|
295
|
+
is_empty_ns = prefix == nil && uri == nil
|
296
|
+
if (is_empty_ns)
|
297
|
+
start = 0
|
298
|
+
else
|
299
|
+
start = @prevVisibleNamespacesStart
|
293
300
|
end
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
if (is_empty_ns)
|
298
|
-
start = 0
|
299
|
-
else
|
300
|
-
start = @prevVisibleNamespacesStart
|
301
|
+
@visibleNamespaces.each{|ns|
|
302
|
+
if (ns.prefix() == "xmlns:"+prefix.to_s() && ns.uri() == uri)
|
303
|
+
return true
|
301
304
|
end
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
# ns = @visibleNamespaces[i]
|
310
|
-
# return true if (ns.prefix() == "xmlns:"+prefix.to_s() && ns.uri() == uri)
|
311
|
-
# #p = ns.prefix() if (ns.prefix().index("xmlns") == 0)
|
312
|
-
# #return ns.uri() == uri if (p == prefix)
|
313
|
-
#}
|
314
|
-
#return is_empty_ns
|
315
|
-
end
|
316
|
-
|
317
|
-
def is_node_visible(node)
|
318
|
-
return true if (@xnl.size() == 0)
|
319
|
-
@xnl.each{|element|
|
320
|
-
return true if (element == node)
|
321
|
-
}
|
322
|
-
return false
|
323
|
-
end
|
324
|
-
|
325
|
-
def normalize_string(input, type)
|
326
|
-
sb = ""
|
327
|
-
return input
|
328
|
-
end
|
329
|
-
#input.each_byte{|b|
|
330
|
-
# if (b ==60 && (type == NODE_TYPE_ATTRIBUTE || is_text_node(type)))
|
331
|
-
# sb = sb + "<"
|
332
|
-
# elsif (b == 62 && is_text_node(type))
|
333
|
-
# sb = sb + ">"
|
334
|
-
# elsif (b == 38 && (is_text_node(type) || is_text_node(type))) #Ampersand
|
335
|
-
# sb = sb + "&"
|
336
|
-
# elsif (b == 34 && is_text_node(type)) #Quote
|
337
|
-
# sb = sb + """
|
338
|
-
# elsif (b == 9 && is_text_node(type)) #Tabulator
|
339
|
-
# sb = sb + "	"
|
340
|
-
# elsif (b == 11 && is_text_node(type)) #CR
|
341
|
-
# sb = sb + "
"
|
342
|
-
# elsif (b == 13 && (type == NODE_TYPE_ATTRIBUTE || (is_text_node(type) && type != NODE_TYPE_WHITESPACE) || type == NODE_TYPE_COMMENT || type == NODE_TYPE_PI))
|
343
|
-
# sb = sb + "
"
|
344
|
-
# elsif (b == 13)
|
345
|
-
# next
|
346
|
-
# else
|
347
|
-
# sb = sb.concat(b)
|
348
|
-
# end
|
305
|
+
}
|
306
|
+
return is_empty_ns
|
307
|
+
#(@visibleNamespaces.size()-1).downto(start) {|i|
|
308
|
+
# ns = @visibleNamespaces[i]
|
309
|
+
# return true if (ns.prefix() == "xmlns:"+prefix.to_s() && ns.uri() == uri)
|
310
|
+
# #p = ns.prefix() if (ns.prefix().index("xmlns") == 0)
|
311
|
+
# #return ns.uri() == uri if (p == prefix)
|
349
312
|
#}
|
350
|
-
#
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
313
|
+
#return is_empty_ns
|
314
|
+
end
|
315
|
+
|
316
|
+
def is_node_visible(node)
|
317
|
+
return true if (@xnl.size() == 0)
|
318
|
+
@xnl.each{|element|
|
319
|
+
return true if (element == node)
|
320
|
+
}
|
321
|
+
return false
|
322
|
+
end
|
323
|
+
|
324
|
+
def normalize_string(input, type)
|
325
|
+
sb = ""
|
326
|
+
return input
|
327
|
+
end
|
328
|
+
#input.each_byte{|b|
|
329
|
+
# if (b ==60 && (type == NODE_TYPE_ATTRIBUTE || is_text_node(type)))
|
330
|
+
# sb = sb + "<"
|
331
|
+
# elsif (b == 62 && is_text_node(type))
|
332
|
+
# sb = sb + ">"
|
333
|
+
# elsif (b == 38 && (is_text_node(type) || is_text_node(type))) #Ampersand
|
334
|
+
# sb = sb + "&"
|
335
|
+
# elsif (b == 34 && is_text_node(type)) #Quote
|
336
|
+
# sb = sb + """
|
337
|
+
# elsif (b == 9 && is_text_node(type)) #Tabulator
|
338
|
+
# sb = sb + "	"
|
339
|
+
# elsif (b == 11 && is_text_node(type)) #CR
|
340
|
+
# sb = sb + "
"
|
341
|
+
# elsif (b == 13 && (type == NODE_TYPE_ATTRIBUTE || (is_text_node(type) && type != NODE_TYPE_WHITESPACE) || type == NODE_TYPE_COMMENT || type == NODE_TYPE_PI))
|
342
|
+
# sb = sb + "
"
|
343
|
+
# elsif (b == 13)
|
344
|
+
# next
|
345
|
+
# else
|
346
|
+
# sb = sb.concat(b)
|
347
|
+
# end
|
348
|
+
#}
|
349
|
+
#sb
|
350
|
+
#end
|
351
|
+
|
352
|
+
def write_text_node(node, visible)
|
353
|
+
if (visible)
|
354
|
+
@res = @res + normalize_string(node.value(), node.node_type())
|
392
355
|
end
|
393
356
|
end
|
394
357
|
|
358
|
+
def white_text?(text)
|
359
|
+
return true if ((text.strip() == "") || (text.strip() == nil))
|
360
|
+
return false
|
361
|
+
end
|
362
|
+
|
363
|
+
def is_namespace_decl(attribute)
|
364
|
+
#return true if (attribute.name() == "xmlns")
|
365
|
+
return true if (attribute.prefix().index("xmlns") == 0)
|
366
|
+
return false
|
367
|
+
end
|
368
|
+
|
369
|
+
def is_text_node(type)
|
370
|
+
return true if (type == NODE_TYPE_TEXT || type == NODE_TYPE_CDATA || type == NODE_TYPE_WHITESPACE)
|
371
|
+
return false
|
372
|
+
end
|
373
|
+
|
374
|
+
def remove_whitespace(string)
|
375
|
+
new_string = ""
|
376
|
+
in_white = false
|
377
|
+
string.each_byte{|b|
|
378
|
+
#if (in_white && b == 32)
|
379
|
+
#else
|
380
|
+
if !(in_white && b == 32)
|
381
|
+
new_string = new_string + b.chr()
|
382
|
+
end
|
383
|
+
if (b == 62) #>
|
384
|
+
in_white = true
|
385
|
+
end
|
386
|
+
if (b == 60) #<
|
387
|
+
in_white = false
|
388
|
+
end
|
389
|
+
}
|
390
|
+
new_string
|
391
|
+
end
|
392
|
+
end
|
393
|
+
|
395
394
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fractalpenguin-googlesso
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- FractalPenguin
|
@@ -18,12 +18,13 @@ extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- lib/FractalPenguinGoogleSSO.rb
|
21
|
-
- lib/processresponse.rb
|
22
|
-
- lib/xmlcanonicalizer.rb
|
23
21
|
- lib/SamlResponseTemplate.xml
|
24
22
|
- lib/SignatureTemplate.xml
|
23
|
+
- lib/processresponse.rb
|
24
|
+
- lib/xmlcanonicalizer.rb
|
25
25
|
homepage: https://github.com/Kylerchrdsn/fractalpenguin-googlesso
|
26
|
-
licenses:
|
26
|
+
licenses:
|
27
|
+
- MIT
|
27
28
|
metadata: {}
|
28
29
|
post_install_message:
|
29
30
|
rdoc_options: []
|
@@ -31,17 +32,17 @@ require_paths:
|
|
31
32
|
- lib
|
32
33
|
required_ruby_version: !ruby/object:Gem::Requirement
|
33
34
|
requirements:
|
34
|
-
- -
|
35
|
+
- - ">="
|
35
36
|
- !ruby/object:Gem::Version
|
36
37
|
version: '0'
|
37
38
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
39
|
requirements:
|
39
|
-
- -
|
40
|
+
- - ">="
|
40
41
|
- !ruby/object:Gem::Version
|
41
42
|
version: '0'
|
42
43
|
requirements: []
|
43
44
|
rubyforge_project:
|
44
|
-
rubygems_version: 2.
|
45
|
+
rubygems_version: 2.4.5
|
45
46
|
signing_key:
|
46
47
|
specification_version: 4
|
47
48
|
summary: Google SSO
|