You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
thrownewNotSupportedException($"{file} is not a valid TOC file, supported TOC files should be either \"{Constants.TableOfContents.MarkdownTocFileName}\" or \"{Constants.TableOfContents.YamlTocFileName}\".");
81
81
}
82
82
}
83
83
catch(Exceptione)
@@ -86,7 +86,45 @@ public static TocItemViewModel LoadSingleToc(string file)
// Reset stream position and discard StreamReader's buffered data.
111
+
reader.BaseStream.Seek(0,SeekOrigin.Begin);
112
+
reader.DiscardBufferedData();
113
+
114
+
// Gets current encoding's BOM bytes.
115
+
varbomBytes=reader.CurrentEncoding.Preamble;
116
+
if(bomBytes.IsEmpty)
117
+
return;
118
+
119
+
// Try to skip BOM bytes. (StreamReader don't skip BOM bytes automatically when calling DiscardBufferedData)
120
+
Span<byte>bytes=stackallocbyte[bomBytes.Length];
121
+
reader.BaseStream.Read(bytes);
122
+
123
+
if(bomBytes.SequenceEqual(bytes))
124
+
return;
89
125
90
-
thrownewNotSupportedException($"{file} is not a valid TOC file, supported TOC files should be either \"{Constants.TableOfContents.MarkdownTocFileName}\" or \"{Constants.TableOfContents.YamlTocFileName}\".");
126
+
// Reset stream position. If header bytes are not matched to expected BOM bytes.
127
+
// This logics are required for StreamReader that is created with `detectEncodingFromByteOrderMarks: true`.
0 commit comments