Remove UTF-8 BOM before JSON detection

Added logic to strip the UTF-8 BOM character from the start of the text before performing JSON format detection. This ensures that files with a BOM are correctly identified as JSON.
This commit is contained in:
ema
2026-01-05 13:37:01 +08:00
parent 352192ad41
commit adc2b0b094

View File

@@ -36,6 +36,10 @@ public sealed class JSONDetector : IFormatDetector
var span = text.AsSpan();
// Remove UTF-8 BOM if present
if (span.Length > 0 && span[0] == '\uFEFF')
span = span.Slice(1);
// TrimStart
int start = 0;
while (start < span.Length && char.IsWhiteSpace(span[start]))