Skip to content

Commit

Permalink
imp - Added unsupported ALTIDs
Browse files Browse the repository at this point in the history
---

We need to filter types that don't support ALTID even if their cardinality allows it.

---

Type: imp
Breaking: False
Doc Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Apr 3, 2024
1 parent 1aa4c83 commit c114894
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
30 changes: 18 additions & 12 deletions VisualCard/Parsers/VcardParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,28 @@ public Card Parse()
// If we have more than one argument, check for ALTID
if (CardVersion.Major >= 4 && type == PartType.PartsArray)
{
if (splitArgs[0].StartsWith(VcardConstants._altIdArgumentSpecifier))
var cardinality = VcardParserTools.GetPartsArrayEnumFromType(classType, CardVersion).Item2;
if (cardinality != PartCardinality.MayBeOneNoAltId && cardinality != PartCardinality.ShouldBeOneNoAltId &&
cardinality != PartCardinality.AtLeastOneNoAltId && cardinality != PartCardinality.AnyNoAltId)
{
// We need ALTID to be numeric
if (!int.TryParse(splitArgs[0].Substring(VcardConstants._altIdArgumentSpecifier.Length), out altId))
throw new InvalidDataException("ALTID must be numeric");
// The type supports ALTID.
if (splitArgs[0].StartsWith(VcardConstants._altIdArgumentSpecifier))
{
// We need ALTID to be numeric
if (!int.TryParse(splitArgs[0].Substring(VcardConstants._altIdArgumentSpecifier.Length), out altId))
throw new InvalidDataException("ALTID must be numeric");

// We need ALTID to be positive
if (altId < 0)
throw new InvalidDataException("ALTID must be positive");
// We need ALTID to be positive
if (altId < 0)
throw new InvalidDataException("ALTID must be positive");

// Here, we require arguments for ALTID
if (splitArgs.Length <= 1)
throw new InvalidDataException("ALTID must have one or more arguments to specify why this instance is an alternative");
// Here, we require arguments for ALTID
if (splitArgs.Length <= 1)
throw new InvalidDataException("ALTID must have one or more arguments to specify why this instance is an alternative");
}
else if (splitArgs.Any((arg) => arg.StartsWith(VcardConstants._altIdArgumentSpecifier)))
throw new InvalidDataException("ALTID must be exactly in the first position of the argument, because arguments that follow it are required to be specified");
}
else if (splitArgs.Any((arg) => arg.StartsWith(VcardConstants._altIdArgumentSpecifier)))
throw new InvalidDataException("ALTID must be exactly in the first position of the argument, because arguments that follow it are required to be specified");
}

// Finalize the arguments
Expand Down
2 changes: 1 addition & 1 deletion VisualCard/Parsers/VcardParserTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ internal static (PartsArrayEnum, PartCardinality) GetPartsArrayEnumFromType(Type
else if (partsArrayType == typeof(XNameInfo))
return (PartsArrayEnum.NonstandardNames, PartCardinality.Any);
else if (partsArrayType == typeof(RevisionInfo))
return (PartsArrayEnum.Revision, PartCardinality.MayBeOne);
return (PartsArrayEnum.Revision, PartCardinality.MayBeOneNoAltId);
else if (partsArrayType == typeof(BirthDateInfo))
return (PartsArrayEnum.Birthdate, PartCardinality.MayBeOne);
else if (partsArrayType == typeof(AnniversaryInfo))
Expand Down
8 changes: 8 additions & 0 deletions VisualCard/Parts/Enums/PartCardinality.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ internal enum PartCardinality
/// </summary>
ShouldBeOne,
/// <summary>
/// Cardinality: * (One or more instances per vCard MAY be present.) - AltID not supported
/// </summary>
AnyNoAltId,
/// <summary>
/// Cardinality: 1* (One or more instances per vCard MUST be present.) - AltID not supported
/// </summary>
AtLeastOneNoAltId,
/// <summary>
/// Cardinality: *1 (Exactly one instance per vCard MAY be present.) - AltID not supported
/// </summary>
MayBeOneNoAltId,
Expand Down

0 comments on commit c114894

Please sign in to comment.