Skip to content

armgit / Filee

Public Imported from GitHub
0

Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.

fix(vcard): fold long combining sequences within 75 octets (#608)

Stamina9548ce52fe6d5
diff --git a/src/Filee.Engines/Data/VCard.cs b/src/Filee.Engines/Data/VCard.cs
index 35aa60d0..78e5c175 100644
--- a/src/Filee.Engines/Data/VCard.cs
+++ b/src/Filee.Engines/Data/VCard.cs
@@ -8,7 +8,6 @@
// CSV → vCard reads those columns (and common other names for them, also in Korean and Chinese) and writes vCard 3.0
// in UTF-8, which phones and mail programs import.
-using System.Globalization;
using System.Text;
using System.Text.RegularExpressions;
@@ -560,19 +559,15 @@ internal static partial class VCard
private static void Line(StringBuilder sb, string line)
{
var bytes = 0;
- var limit = 75;
- var e = StringInfo.GetTextElementEnumerator(line);
- while (e.MoveNext())
+ foreach (var rune in line.EnumerateRunes())
{
- var element = e.GetTextElement();
- var size = Encoding.UTF8.GetByteCount(element);
- if (bytes + size > limit)
+ var size = rune.Utf8SequenceLength;
+ if (bytes + size > 75)
{
sb.Append("\r\n ");
bytes = 1;
- limit = 75;
}
- sb.Append(element);
+ sb.Append(rune.ToString());
bytes += size;
}
sb.Append("\r\n");
diff --git a/tests/Filee.Engines.Tests/VCardTests.cs b/tests/Filee.Engines.Tests/VCardTests.cs
index ff343b84..a6313428 100644
--- a/tests/Filee.Engines.Tests/VCardTests.cs
+++ b/tests/Filee.Engines.Tests/VCardTests.cs
@@ -5,6 +5,7 @@
using System.Text;
using Filee.Core.Conversion;
using Filee.Core.Presets;
+using Filee.Engines.Data;
namespace Filee.Engines.Tests;
@@ -136,4 +137,17 @@ public class VCardTests(EngineFixture fx) : IClassFixture<EngineFixture>
Assert.Equal(JobState.Failed, job.State);
Assert.Contains("No contact columns", job.Files.Single().ErrorDetail);
}
+
+ [Fact]
+ public void Long_combining_sequence_folds_within_seventy_five_octets_and_roundtrips()
+ {
+ var name = "e" + new string('\u0301', 40);
+ var text = VCard.Write([new Contact { FullName = name }]);
+
+ // The continuation space is followed by a combining mark; compare the protocol marker literally.
+ Assert.Contains("\r\n ", text, StringComparison.Ordinal);
+ Assert.All(text.Split("\r\n", StringSplitOptions.RemoveEmptyEntries),
+ line => Assert.True(Encoding.UTF8.GetByteCount(line) <= 75, line));
+ Assert.Equal(name, Assert.Single(VCard.Read(Encoding.UTF8.GetBytes(text))).FullName);
+ }
}