Skip to content
This repository was archived by the owner on Oct 14, 2021. It is now read-only.

Commit 85712ec

Browse files
authored
Fix XmlSignature search ID (#54)
1 parent f5ea6d9 commit 85712ec

File tree

2 files changed

+82
-13
lines changed

2 files changed

+82
-13
lines changed

dotnet/dotnetframework/GeneXusXmlSignature/GeneXusXmlSignature.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
<ErrorReport>prompt</ErrorReport>
3838
<WarningLevel>4</WarningLevel>
3939
</PropertyGroup>
40+
<PropertyGroup>
41+
<StartupObject />
42+
</PropertyGroup>
4043
<ItemGroup>
4144
<Reference Include="System" />
4245
<Reference Include="System.Core" />

dotnet/dotnetframework/GeneXusXmlSignature/Utils/SignatureUtils.cs

Lines changed: 79 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -150,37 +150,103 @@ internal static bool validateExtensionSchema(string path)
150150
}
151151

152152

153-
internal static XmlNode getNodeFromID(XmlDocument doc, string id, string xPath, Error error)
153+
/* internal static XmlNode getNodeFromID(XmlDocument doc, string id, string xPath, Error error)
154+
{
155+
if (id == null || SecurityUtils.compareStrings(id, ""))
156+
{
157+
error.setError("SU010", "Error, id data is empty");
158+
return null;
159+
}
160+
string idToFind = xPath.Substring(1);
161+
XmlNode rootNode = doc.DocumentElement;
162+
XmlNodeList allNodes = rootNode.ChildNodes;
163+
foreach (XmlNode node in allNodes)
164+
{
165+
166+
XmlAttributeCollection attributes = node.Attributes;
167+
if (attributes != null)
168+
{
169+
foreach (XmlAttribute attribute in node.Attributes)
170+
{
171+
if (SecurityUtils.compareStrings(attribute.Name, id) && SecurityUtils.compareStrings(attribute.Value, idToFind))
172+
{
173+
return node;
174+
}
175+
}
176+
}
177+
178+
179+
}
180+
error.setError("SU009", "Could not found element attribute " + id + " with id: " + idToFind);
181+
return null;
182+
}*/
183+
184+
internal static XmlNode getNodeFromID(XmlDocument doc, String id, String xPath, Error error)
154185
{
155186
if (id == null || SecurityUtils.compareStrings(id, ""))
156187
{
157188
error.setError("SU010", "Error, id data is empty");
158189
return null;
159190
}
160191
string idToFind = xPath.Substring(1);
161-
XmlNode rootNode = doc.DocumentElement;
162-
XmlNodeList allNodes = rootNode.ChildNodes;
163-
foreach (XmlNode node in allNodes)
192+
XmlNode root = doc.DocumentElement;
193+
XmlNodeList allNodes = root.ChildNodes;
194+
195+
XmlNode n = RecursivegetNodeFromID(allNodes, id, idToFind);
196+
if (n == null)
164197
{
198+
error.setError("SU009", "Could not find element with id " + idToFind);
199+
}
200+
return n;
165201

166-
XmlAttributeCollection attributes = node.Attributes;
167-
if (attributes != null)
202+
}
203+
204+
private static XmlNode FindAttribute(XmlNode node, String id, String idToFind)
205+
{
206+
XmlAttributeCollection attributes = node.Attributes;
207+
if (attributes != null)
208+
{
209+
foreach (XmlAttribute attribute in node.Attributes)
168210
{
169-
foreach (XmlAttribute attribute in node.Attributes)
211+
if (SecurityUtils.compareStrings(attribute.Name, id) && SecurityUtils.compareStrings(attribute.Value, idToFind))
170212
{
171-
if (SecurityUtils.compareStrings(attribute.Name, id) && SecurityUtils.compareStrings(attribute.Value, idToFind))
213+
return node;
214+
}
215+
}
216+
}
217+
return null;
218+
}
219+
220+
private static XmlNode RecursivegetNodeFromID(XmlNodeList list, String id, String idToFind)
221+
{
222+
if (list.Count == 0)
223+
{
224+
return null;
225+
}
226+
else
227+
{
228+
for (int i = 0; i < list.Count; i++)
229+
{
230+
XmlNode node = FindAttribute(list.Item(i), id, idToFind);
231+
if (node == null)
232+
{
233+
XmlNode n1 = RecursivegetNodeFromID(list.Item(i).ChildNodes, id, idToFind);
234+
if (n1 != null)
172235
{
173-
return node;
236+
return n1;
174237
}
175238
}
239+
else
240+
{
241+
return node;
242+
}
176243
}
177-
178-
244+
return null;
179245
}
180-
error.setError("SU009", "Could not found element attribute " + id + " with id: " + idToFind);
181-
return null;
182246
}
183247

248+
249+
184250
internal static string getIDNodeValue(XmlDocument doc)
185251
{
186252
doc.PreserveWhitespace = true;

0 commit comments

Comments
 (0)