Skip to content

Commit

Permalink
Use enumerator to iterate items in the specified enumeration, and ins…
Browse files Browse the repository at this point in the history
…ert them to the lazily created dictionary if they pass the validations.
  • Loading branch information
carlossanlop committed Apr 4, 2023
1 parent d690c9e commit a6ca6ae
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,13 @@ internal TarHeader(TarEntryFormat format, TarEntryType typeFlag, TarHeader other
internal void InitializeExtendedAttributesWithExisting(IEnumerable<KeyValuePair<string, string>> existing)
{
Debug.Assert(_ea == null);
_ea = new Dictionary<string, string>(existing);
foreach (KeyValuePair<string, string> kvp in _ea)
Debug.Assert(existing != null);

using IEnumerator<KeyValuePair<string, string>> enumerator = existing.GetEnumerator();
while (enumerator.MoveNext())
{
KeyValuePair<string, string> kvp = enumerator.Current;

int index = kvp.Key.IndexOfAny(new char[] { '=', '\n' });
if (index >= 0)
{
Expand All @@ -125,6 +129,10 @@ internal void InitializeExtendedAttributesWithExisting(IEnumerable<KeyValuePair<
{
throw new ArgumentException(SR.Format(SR.TarExtAttrDisallowedValueChar, kvp.Key, "\\n"));
}

_ea ??= new Dictionary<string, string>();

_ea.Add(kvp.Key, kvp.Value);
}
}

Expand Down

0 comments on commit a6ca6ae

Please sign in to comment.