-
-
Notifications
You must be signed in to change notification settings - Fork 107
Open
Labels
Description
Hello! Using the latest version of SmartFormat, I encountered an issue, where my template cannot be processed when it contains Cyrillic letters.
The code:
using SmartFormat;
namespace TestSmartFormat
{
public class AttributeData
{
public string DisplayText { get; set; }
}
public class Document
{
public Dictionary<string, AttributeData> ArchiveAttributes { get; set; }
}
public class UnifiedDocumentData
{
public Document Document { get; set; }
}
class Program
{
static void Main(string[] args)
{
// Initialize sample data with Cyrillic keys
var data = new UnifiedDocumentData
{
Document = new Document
{
ArchiveAttributes = new Dictionary<string, AttributeData>
{
{ "София", new AttributeData { DisplayText = "София" } },
{ "Пловдив", new AttributeData { DisplayText = "Пловдив" } }
}
}
};
// Define templates
string template1 = "{ArchiveAttributes[София].DisplayText}";
string template2 = "{ArchiveAttributes[Пловдив].DisplayText}";
var formatter = Smart.CreateDefaultSmartFormat();
try
{
// Perform formatting
string result1 = formatter.Format(template1, data.Document);
string result2 = formatter.Format(template2, data.Document);
// Display results
Console.WriteLine($"Template 1 Result: {result1}"); // Expected: София
Console.WriteLine($"Template 2 Result: {result2}"); // Expected: Пловдив
}
catch (Exception ex)
{
Console.WriteLine($"Unexpected Error: {ex.Message}");
}
}
}
}
The error:
Unexpected Error: The format string has 5 issues:
'0x421': Invalid character in the selector, '0x43E': Invalid character in the selector, '0x444': Invalid character in the selector, '0x438': Invalid character in the selector, '0x44F': Invalid character in the selector
In: "{ArchiveAttributes[София].DisplayText}"
At: -------------------^^^^^
However, when I change the following part to contain only English, it works perfectly well:
var data = new UnifiedDocumentData
{
Document = new Document
{
ArchiveAttributes = new Dictionary<string, AttributeData>
{
{ "Sofia", new AttributeData { DisplayText = "София" } },
{ "Plovdiv", new AttributeData { DisplayText = "Пловдив" } }
}
}
};
// Define templates
string template1 = "{ArchiveAttributes[Sofia].DisplayText}";
string template2 = "{ArchiveAttributes[Plovdiv].DisplayText}";
I am unsure if I am missing something, or if it is genuinely a bug.
Thanks in advance for your help!