Skip to content

Commit

Permalink
Avoid crashing on large file
Browse files Browse the repository at this point in the history
  • Loading branch information
niksedk committed Sep 14, 2023
1 parent 249a26c commit 32706a4
Showing 1 changed file with 25 additions and 30 deletions.
55 changes: 25 additions & 30 deletions src/XmlContentTranslator/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,45 +312,40 @@ private void AddListViewItem(XmlNode node)
{
if (listViewLanguageTags.Columns.Count == 2)
{
if (node.NodeType != XmlNodeType.Comment && node.NodeType != XmlNodeType.CDATA)
if (node.NodeType == XmlNodeType.Comment || node.NodeType == XmlNodeType.CDATA)
{
return;
}

ListViewItem item;
if (node.NodeType == XmlNodeType.Attribute)
{
item = new ListViewItem("@" + node.Name);
item.SubItems.Add(node.InnerText);
}
else if (XmlUtils.ContainsText(node))
{
item = new ListViewItem(node.Name);
item.SubItems.Add(node.InnerXml);
}
else
{
item = new ListViewItem(node.Name);
item.SubItems.Add(node.InnerText);
}
ListViewItem item;
if (node.NodeType == XmlNodeType.Attribute)
{
item = new ListViewItem("@" + node.Name);
item.SubItems.Add(node.InnerText);
}
else if (XmlUtils.ContainsText(node))
{
item = new ListViewItem(node.Name);
item.SubItems.Add(node.InnerXml);
}
else
{
item = new ListViewItem(node.Name);
item.SubItems.Add(node.InnerText);
}


item.Tag = node;
listViewLanguageTags.Items.Add(item);
ListViewItemComparer.NoSortOrder.Add(item, listViewLanguageTags.Items.Count);
item.Tag = node;
listViewLanguageTags.Items.Add(item);
ListViewItemComparer.NoSortOrder.Add(item, listViewLanguageTags.Items.Count);

_listViewItemHashtable.Add(XmlUtils.BuildNodePath(node), item); // fails on some attributes!!
}
_listViewItemHashtable.Add(XmlUtils.BuildNodePath(node), item); // fails on some attributes!!
}
else if (listViewLanguageTags.Columns.Count == 3)
{
var item = _listViewItemHashtable[XmlUtils.BuildNodePath(node)] as ListViewItem;

if (XmlUtils.ContainsText(node))
{
item?.SubItems.Add(node.InnerXml);
}
else
if (_listViewItemHashtable[XmlUtils.BuildNodePath(node)] is ListViewItem item && item.SubItems.Count < 4096)
{
item?.SubItems.Add(node.InnerText);
item.SubItems.Add(XmlUtils.ContainsText(node) ? node.InnerXml : node.InnerText);
}
}
}
Expand Down

0 comments on commit 32706a4

Please sign in to comment.