Skip to content

Commit

Permalink
imp - Property names are case-insensitive
Browse files Browse the repository at this point in the history
---

When parsing, all property names are case-insensitive.

---

Type: imp
Breaking: False
Doc Required: False
Backport Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Oct 2, 2024
1 parent 7a176ba commit beae7e6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
18 changes: 9 additions & 9 deletions VisualCard.Calendar/CalendarTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ public static Parts.Calendar[] GetCalendars(StreamReader stream)
if (!stream.EndOfStream)
continue;
}
else if (CalendarLine != VCalendarConstants._beginText &&
!CalendarLine.StartsWith(VCalendarConstants._versionSpecifier) &&
CalendarLine != VCalendarConstants._endText)
else if (!CalendarLine.EqualsNoCase(VCalendarConstants._beginText) &&
!CalendarLine.ToUpper().StartsWith(VCalendarConstants._versionSpecifier) &&
!CalendarLine.EqualsNoCase(VCalendarConstants._endText))
append = true;
if (append)
CalendarContent.Append(CalendarLine);

// All vCalendars must begin with BEGIN:VCALENDAR
if (CalendarLine != VCalendarConstants._beginText && !BeginSpotted)
if (!CalendarLine.EqualsNoCase(VCalendarConstants._beginText) && !BeginSpotted)
throw new InvalidDataException($"This is not a valid vCalendar file.");
else if (!BeginSpotted)
{
Expand All @@ -111,20 +111,20 @@ public static Parts.Calendar[] GetCalendars(StreamReader stream)

// Now that the beginning of the calendar tag is spotted, parse the version as we need to know how to select the appropriate parser.
// All vCalendars are required to have their own version directly after the BEGIN:VCALENDAR tag
if (CalendarLine.StartsWith(VCalendarConstants._versionSpecifier) &&
CalendarLine != $"{VCalendarConstants._versionSpecifier}:1.0" &&
CalendarLine != $"{VCalendarConstants._versionSpecifier}:2.0" &&
if (CalendarLine.ToUpper().StartsWith(VCalendarConstants._versionSpecifier) &&
!CalendarLine.EqualsNoCase($"{VCalendarConstants._versionSpecifier}:1.0") &&
!CalendarLine.EqualsNoCase($"{VCalendarConstants._versionSpecifier}:2.0") &&
!VersionSpotted)
throw new InvalidDataException($"This has an invalid vCalendar version {CalendarLine}.");
else if (!VersionSpotted && CalendarLine.StartsWith(VCalendarConstants._versionSpecifier))
else if (!VersionSpotted && CalendarLine.ToUpper().StartsWith(VCalendarConstants._versionSpecifier))
{
VersionSpotted = true;
CalendarVersion = new(CalendarLine.Substring(8));
continue;
}

// If the ending tag is spotted, reset everything.
if (CalendarLine == VCalendarConstants._endText && !EndSpotted)
if (CalendarLine.EqualsNoCase(VCalendarConstants._endText) && !EndSpotted)
{
EndSpotted = true;

Expand Down
5 changes: 3 additions & 2 deletions VisualCard.Calendar/Parsers/VCalendarParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public Parts.Calendar Parse()
throw new ArgumentException("The line must contain an argument delimiter.");
string value = _value.Substring(_value.IndexOf(VCalendarConstants._argumentDelimiter) + 1);
string prefixWithArgs = _value.Substring(0, _value.IndexOf(VCalendarConstants._argumentDelimiter));
string prefix = prefixWithArgs.Contains(';') ? prefixWithArgs.Substring(0, prefixWithArgs.IndexOf(';')) : prefixWithArgs;
string prefix = (prefixWithArgs.Contains(';') ? prefixWithArgs.Substring(0, prefixWithArgs.IndexOf(';')) : prefixWithArgs).ToUpper();
string args = prefixWithArgs.Contains(';') ? prefixWithArgs.Substring(prefix.Length + 1) : "";
string[] splitArgs = args.Split([VCalendarConstants._fieldDelimiter], StringSplitOptions.RemoveEmptyEntries);
string[] splitValues = value.Split([VCalendarConstants._fieldDelimiter], StringSplitOptions.RemoveEmptyEntries);
Expand All @@ -118,7 +118,8 @@ public Parts.Calendar Parse()
// Check to see if we have a BEGIN or an END prefix
if (prefix == VCalendarConstants._beginSpecifier)
{
begins.Add((value, GetCalendarInheritedInstance(value)));
string finalType = value.ToUpper();
begins.Add((finalType, GetCalendarInheritedInstance(finalType)));
continue;
}
else if (prefix == VCalendarConstants._endSpecifier)
Expand Down
30 changes: 15 additions & 15 deletions VisualCard/CardTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,23 @@ public static Card[] GetCards(StreamReader stream)
if (!stream.EndOfStream)
continue;
}
else if (CardLine != VcardConstants._beginText &&
!CardLine.StartsWith(VcardConstants._versionSpecifier) &&
CardLine != VcardConstants._endText)
else if (!CardLine.EqualsNoCase(VcardConstants._beginText) &&
!CardLine.ToUpper().StartsWith(VcardConstants._versionSpecifier) &&
!CardLine.EqualsNoCase(VcardConstants._endText))
append = true;
else if (CardLine == VcardConstants._beginText && nested)
else if (CardLine.EqualsNoCase(VcardConstants._beginText) && nested)
{
// We have a nested card!
StringBuilder nestedBuilder = new();
int nestLevel = 1;
nestedBuilder.AppendLine(CardLine);
while (CardLine != VcardConstants._endText)
while (!CardLine.EqualsNoCase(VcardConstants._endText))
{
CardLine = stream.ReadLine();
nestedBuilder.AppendLine(CardLine);
if (CardLine == VcardConstants._beginText)
if (CardLine.EqualsNoCase(VcardConstants._beginText))
nestLevel++;
else if (CardLine == VcardConstants._endText && nestLevel > 1)
else if (CardLine.EqualsNoCase(VcardConstants._endText) && nestLevel > 1)
{
nestLevel--;
CardLine = "";
Expand All @@ -128,7 +128,7 @@ public static Card[] GetCards(StreamReader stream)
CardContent.Append(CardLine);

// All VCards must begin with BEGIN:VCARD
if (CardLine != VcardConstants._beginText && !BeginSpotted)
if (!CardLine.EqualsNoCase(VcardConstants._beginText) && !BeginSpotted)
throw new InvalidDataException($"This is not a valid VCard contact file.");
else if (!BeginSpotted)
{
Expand All @@ -143,14 +143,14 @@ public static Card[] GetCards(StreamReader stream)
// Now that the beginning of the card tag is spotted, parse the version as we need to know how to select the appropriate parser.
// vCard 4.0 and 5.0 cards are required to have their own version directly after the BEGIN:VCARD tag, but vCard 3.0 and 2.1 may
// or may not place VERSION directly after the BEGIN:VCARD tag.
if (CardLine.StartsWith(VcardConstants._versionSpecifier) &&
CardLine != $"{VcardConstants._versionSpecifier}:2.1" &&
CardLine != $"{VcardConstants._versionSpecifier}:3.0" &&
CardLine != $"{VcardConstants._versionSpecifier}:4.0" &&
CardLine != $"{VcardConstants._versionSpecifier}:5.0" &&
if (CardLine.ToUpper().StartsWith(VcardConstants._versionSpecifier) &&
!CardLine.EqualsNoCase($"{VcardConstants._versionSpecifier}:2.1") &&
!CardLine.EqualsNoCase($"{VcardConstants._versionSpecifier}:3.0") &&
!CardLine.EqualsNoCase($"{VcardConstants._versionSpecifier}:4.0") &&
!CardLine.EqualsNoCase($"{VcardConstants._versionSpecifier}:5.0") &&
!VersionSpotted)
throw new InvalidDataException($"This has an invalid VCard version {CardLine}.");
else if (!VersionSpotted && CardLine.StartsWith(VcardConstants._versionSpecifier))
else if (!VersionSpotted && CardLine.ToUpper().StartsWith(VcardConstants._versionSpecifier))
{
VersionSpotted = true;
CardVersion = new(CardLine.Substring(8));
Expand All @@ -164,7 +164,7 @@ public static Card[] GetCards(StreamReader stream)
versionDirect = false;

// If the ending tag is spotted, reset everything.
if (CardLine == VcardConstants._endText && !EndSpotted)
if (CardLine.EqualsNoCase(VcardConstants._endText) && !EndSpotted)
{
EndSpotted = true;
nested = false;
Expand Down
2 changes: 1 addition & 1 deletion VisualCard/Parsers/VcardParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public Card Parse()
throw new ArgumentException("The line must contain an argument delimiter.");
string value = _value.Substring(_value.IndexOf(VcardConstants._argumentDelimiter) + 1);
string prefixWithArgs = _value.Substring(0, _value.IndexOf(VcardConstants._argumentDelimiter));
string prefix = prefixWithArgs.Contains(';') ? prefixWithArgs.Substring(0, prefixWithArgs.IndexOf(';')) : prefixWithArgs;
string prefix = (prefixWithArgs.Contains(';') ? prefixWithArgs.Substring(0, prefixWithArgs.IndexOf(';')) : prefixWithArgs).ToUpper();
string args = prefixWithArgs.Contains(';') ? prefixWithArgs.Substring(prefix.Length + 1) : "";
string[] splitArgs = args.Split([VcardConstants._fieldDelimiter], StringSplitOptions.RemoveEmptyEntries);
string[] splitValues = value.Split([VcardConstants._fieldDelimiter], StringSplitOptions.RemoveEmptyEntries);
Expand Down

0 comments on commit beae7e6

Please sign in to comment.