Skip to content

Commit

Permalink
imp - Parse all string values
Browse files Browse the repository at this point in the history
---

We need to parse all the string values to ensure that no invalid data is being entered.

---

Type: imp
Breaking: False
Doc Required: False
Backport Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Oct 1, 2024
1 parent c089b0e commit f5fb073
Show file tree
Hide file tree
Showing 14 changed files with 175 additions and 123 deletions.
14 changes: 6 additions & 8 deletions VisualCard.Calendar/Parsers/VCalendarParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ public Parts.Calendar Parse()

// Handle the part type
Type calendarType = subPart is not null ? subPart.GetType() : calendar.GetType();
string valueType = VcardCommonTools.GetFirstValue(splitArgs, defaultValue, VCalendarConstants._valueArgumentSpecifier);
string valueType = VcardCommonTools.GetFirstValue(splitArgs, defaultValueType, VCalendarConstants._valueArgumentSpecifier);
string finalValue = VcardParserTools.ProcessStringValue(value, valueType);
switch (type)
{
case PartType.Strings:
Expand All @@ -178,9 +179,6 @@ public Parts.Calendar Parse()
if (!supported)
continue;

// Get the final value
string finalValue = VcardParserTools.ProcessStringValue(value, valueType);

// Set the string for real
if (subPart is not null)
subPart.SetString(stringType, finalValue);
Expand All @@ -196,13 +194,13 @@ public Parts.Calendar Parse()
continue;

// Get the final value
double finalValue = VcardParserTools.ProcessIntegerValue(value, valueType);
double finalDouble = double.Parse(finalValue);

// Set the integer for real
if (subPart is not null)
subPart.SetInteger(integerType, finalValue);
subPart.SetInteger(integerType, finalDouble);
else
calendar.SetInteger(integerType, finalValue);
calendar.SetInteger(integerType, finalDouble);
}
break;
case PartType.PartsArray:
Expand All @@ -216,7 +214,7 @@ public Parts.Calendar Parse()
continue;

// Now, get the part info
string finalValue = partsArrayType is CalendarPartsArrayEnum.IanaNames or CalendarPartsArrayEnum.NonstandardNames ? _value : value;
finalValue = partsArrayType is CalendarPartsArrayEnum.IanaNames or CalendarPartsArrayEnum.NonstandardNames ? _value : value;
var partInfo = fromString(finalValue, [.. finalArgs], elementTypes, valueType, CalendarVersion);

// Set the array for real
Expand Down
90 changes: 45 additions & 45 deletions VisualCard.Calendar/Parsers/VCalendarParserTools.cs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions VisualCard.Calendar/Parts/Calendar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,14 @@ internal string SaveToString(Version version, Dictionary<CalendarPartsArrayEnum,
string prefix = VCalendarParserTools.GetPrefixFromPartsArrayEnum(partsArrayEnum);
var type = VCalendarParserTools.GetPartType(prefix);
string defaultType = type.defaultType;
string defaultValue = type.defaultValue;
string defaultValueType = type.defaultValueType;

// Now, assemble the line
foreach (var part in array)
{
var partBuilder = new StringBuilder();
string partRepresentation = part.ToStringVcalendarInternal(version);
string partArguments = CalendarBuilderTools.BuildArguments(part, defaultType, defaultValue);
string partArguments = CalendarBuilderTools.BuildArguments(part, defaultType, defaultValueType);
string[] partArgumentsLines = partArguments.SplitNewLines();
partBuilder.Append($"{prefix}");
partBuilder.Append($"{partArguments}");
Expand Down
1 change: 1 addition & 0 deletions VisualCard.ShowContacts/TestFiles/picture.vcf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ VERSION:2.1
N:ViceCity;EoflaOE;;;
FN:EoflaOE ViceCity
X-ANDROID-CUSTOM:vnd.android.cursor.item/nickname;AptiviCEO;;;;;;;;;;;;;;
PHOTO;VALUE=uri:http://www.example.com/pub/photos/jqpublic.gif
PHOTO;ENCODING=BASE64;PNG:iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAYAAADimHc4AAAA
AXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAACAASURBVHichX1ps2XJVd3K4Yx3eEMNXa2eh
CSEaIxtZAMy2EQYGySDQ8YjAeFgCGGHA4fxX/D/8xd/tMETGix1V9Ub7nDuPUNm+sMeTp77qi
Expand Down
1 change: 1 addition & 0 deletions VisualCard.Tests/Recurrence/RecurrenceV1ParseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using Shouldly;
using System;
using VisualCard.Calendar.Parsers.Recurrence;

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV1ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV1ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV1ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV1ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV1ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV1ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV1ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV1ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV1ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV1ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV1ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV1ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV1ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV1ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV1ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV1ParseTests.cs

View workflow job for this annotation

GitHub Actions / Make API Reference

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV1ParseTests.cs

View workflow job for this annotation

GitHub Actions / Make API Reference

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV1ParseTests.cs

View workflow job for this annotation

GitHub Actions / Make API Reference

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV1ParseTests.cs

View workflow job for this annotation

GitHub Actions / Make API Reference

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV1ParseTests.cs

View workflow job for this annotation

GitHub Actions / Make API Reference

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV1ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV1ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV1ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV1ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV1ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)
using VisualCard.Parsers.Recurrence;

namespace VisualCard.Tests.Recurrence
{
Expand Down
1 change: 1 addition & 0 deletions VisualCard.Tests/Recurrence/RecurrenceV2ParseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using Shouldly;
using System;
using VisualCard.Calendar.Parsers.Recurrence;

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV2ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV2ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV2ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV2ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV2ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV2ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV2ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV2ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV2ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV2ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV2ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV2ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV2ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV2ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV2ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV2ParseTests.cs

View workflow job for this annotation

GitHub Actions / Make API Reference

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV2ParseTests.cs

View workflow job for this annotation

GitHub Actions / Make API Reference

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV2ParseTests.cs

View workflow job for this annotation

GitHub Actions / Make API Reference

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV2ParseTests.cs

View workflow job for this annotation

GitHub Actions / Make API Reference

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV2ParseTests.cs

View workflow job for this annotation

GitHub Actions / Make API Reference

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV2ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV2ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV2ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV2ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)

Check failure on line 23 in VisualCard.Tests/Recurrence/RecurrenceV2ParseTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'Recurrence' does not exist in the namespace 'VisualCard.Calendar.Parsers' (are you missing an assembly reference?)
using VisualCard.Parsers.Recurrence;

namespace VisualCard.Tests.Recurrence
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
using System.Collections.Generic;
using System.Globalization;
using VisualCard.Parsers;
using VisualCard.Parsers.Recurrence;

namespace VisualCard.Calendar.Parsers.Recurrence
namespace VisualCard.Parsers.Recurrence
{
/// <summary>
/// Recurrence rule parser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
using System.Collections.Generic;
using System.Linq;
using VisualCard.Parsers;
using VisualCard.Parsers.Recurrence;

namespace VisualCard.Calendar.Parsers.Recurrence
namespace VisualCard.Parsers.Recurrence
{
/// <summary>
/// Recurrence rule parser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
using System.Collections.Generic;
using System.Diagnostics;

namespace VisualCard.Calendar.Parsers.Recurrence
namespace VisualCard.Parsers.Recurrence
{
/// <summary>
/// Recurrence rule instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

namespace VisualCard.Calendar.Parsers.Recurrence
namespace VisualCard.Parsers.Recurrence
{
/// <summary>
/// Recurrence rule frequency
Expand Down
1 change: 1 addition & 0 deletions VisualCard/Parsers/VcardCommonTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public static DateTimeOffset ParsePosixDate(string posixDateRepresentation, bool
return date;
throw new ArgumentException($"Can't parse date {posixDateRepresentation}");
}

/// <summary>
/// Tries to parse the POSIX date formatted with the representation according to the vCard and vCalendar specifications
/// </summary>
Expand Down
6 changes: 2 additions & 4 deletions VisualCard/Parsers/VcardParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,13 @@ public Card Parse()

// Handle the part type
string valueType = VcardCommonTools.GetFirstValue(splitArgs, defaultValueType, VcardConstants._valueArgumentSpecifier);
string finalValue = VcardParserTools.ProcessStringValue(value, valueType);
switch (type)
{
case PartType.Strings:
{
StringsEnum stringType = (StringsEnum)enumeration;

// Get the final value
string finalValue = VcardParserTools.ProcessStringValue(value, valueType);

// Let VisualCard know that we've explicitly specified a kind.
if (stringType == StringsEnum.Kind)
{
Expand All @@ -209,7 +207,7 @@ public Card Parse()
continue;

// Now, get the part info
string finalValue = partsArrayType is PartsArrayEnum.NonstandardNames or PartsArrayEnum.IanaNames ? _value : value;
finalValue = partsArrayType is PartsArrayEnum.NonstandardNames or PartsArrayEnum.IanaNames ? _value : value;
var partInfo = fromString(finalValue, [.. finalArgs], altId, elementTypes, group, valueType, CardVersion);

// Set the array for real
Expand Down
Loading

0 comments on commit f5fb073

Please sign in to comment.