Skip to content

Commit

Permalink
imp - Handle newlines in strings properly
Browse files Browse the repository at this point in the history
---

When saving vCards and vCalendars, we need to handle the strings properly and to handle the newlines so that we don't don't write anything to the first column of the next wrapped line.

---

Type: imp
Breaking: False
Doc Required: False
Backport Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Sep 2, 2024
1 parent dba942e commit d259830
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
9 changes: 6 additions & 3 deletions VisualCard.Calendar/Parsers/VCalendarParserTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,12 @@ internal static string MakeStringBlock(string target, int firstLength)
int processed = 0;
for (int currCharNum = 0; currCharNum < target.Length; currCharNum++)
{
block.Append(target[currCharNum]);
processed++;
if (processed >= selectedMax)
if (target[currCharNum] != '\n' && target[currCharNum] != '\r')
{
block.Append(target[currCharNum]);
processed++;
}
if (processed >= selectedMax || target[currCharNum] == '\n')
{
// Append a new line because we reached the maximum limit
selectedMax = maxChars;
Expand Down
3 changes: 2 additions & 1 deletion VisualCard.Calendar/Parts/Calendar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ internal string SaveToString(Version version, Dictionary<CalendarPartsArrayEnum,

// Now, locate the prefix and assemble the line
string prefix = VCalendarParserTools.GetPrefixFromStringsEnum(stringEnum);
cardBuilder.AppendLine($"{prefix}{VCalendarConstants._argumentDelimiter}{stringValue}");
cardBuilder.Append($"{prefix}{VCalendarConstants._argumentDelimiter}");
cardBuilder.AppendLine($"{VCalendarParserTools.MakeStringBlock(stringValue, prefix.Length)}");
}

// Then, enumerate all the arrays
Expand Down
9 changes: 6 additions & 3 deletions VisualCard/Parsers/VcardParserTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,12 @@ internal static string MakeStringBlock(string target, int firstLength)
int processed = 0;
for (int currCharNum = 0; currCharNum < target.Length; currCharNum++)
{
block.Append(target[currCharNum]);
processed++;
if (processed >= selectedMax)
if (target[currCharNum] != '\n' && target[currCharNum] != '\r')
{
block.Append(target[currCharNum]);
processed++;
}
if (processed >= selectedMax || target[currCharNum] == '\n')
{
// Append a new line because we reached the maximum limit
selectedMax = maxChars;
Expand Down
3 changes: 2 additions & 1 deletion VisualCard/Parts/Card.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ public string SaveToString()

// Now, locate the prefix and assemble the line
string prefix = VcardParserTools.GetPrefixFromStringsEnum(stringEnum);
cardBuilder.AppendLine($"{prefix}{VcardConstants._argumentDelimiter}{stringValue}");
cardBuilder.Append($"{prefix}{VcardConstants._argumentDelimiter}");
cardBuilder.AppendLine($"{VcardParserTools.MakeStringBlock(stringValue, prefix.Length)}");
}

// Then, enumerate all the arrays
Expand Down

0 comments on commit d259830

Please sign in to comment.