Skip to content

Commit 703ff4b

Browse files
committed
Readd FormC normalization for select platforms
1 parent c57b850 commit 703ff4b

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

src/Core/SecureFolderFS.Core.FileSystem/Helpers/Paths/Abstract/AbstractPathHelpers.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.IO;
3+
using System.Text;
34
using SecureFolderFS.Core.Cryptography;
45

56
namespace SecureFolderFS.Core.FileSystem.Helpers.Paths.Abstract
@@ -26,9 +27,21 @@ public static ReadOnlySpan<char> RemoveCiphertextExtension(string ciphertextName
2627
// codepoints, the string may contain spurious dot-like characters that confuse the
2728
// path parser, causing it to truncate mid-ciphertext.
2829
// Strip the known extension manually instead.
29-
return ciphertextName.EndsWith(Constants.Names.ENCRYPTED_FILE_EXTENSION, StringComparison.Ordinal)
30+
var nameWithoutExtension = ciphertextName.EndsWith(Constants.Names.ENCRYPTED_FILE_EXTENSION, StringComparison.Ordinal)
3031
? ciphertextName.AsSpan(0, ciphertextName.Length - Constants.Names.ENCRYPTED_FILE_EXTENSION.Length)
3132
: ciphertextName.AsSpan();
33+
34+
if (OperatingSystem.IsAndroid() || OperatingSystem.IsMacOS() || OperatingSystem.IsMacCatalyst())
35+
{
36+
var normalizedLength = nameWithoutExtension.GetNormalizedLength(NormalizationForm.FormC);
37+
var normalized = new char[normalizedLength];
38+
39+
// NFC-normalize before decoding
40+
if (nameWithoutExtension.TryNormalize(normalized, out var written, NormalizationForm.FormC))
41+
return normalized.AsSpan(0, written);
42+
}
43+
44+
return nameWithoutExtension;
3245
}
3346
}
3447
}

0 commit comments

Comments
 (0)