Closed delphidabbler closed 1 month ago
TFileIO.CheckBOM has a bug where it returns true for zero length preambles instead of false. Fixed this in cupola as follows:
TFileIO.CheckBOM
cupola
class function TFileIO.CheckBOM(const Stream: TStream; const Encoding: TEncoding): Boolean; var Bytes: TBytes; Preamble: TBytes; OldPos: Int64; begin Assert(Assigned(Stream), 'TFileIO.CheckBOM: Stream is nil'); Assert(Assigned(Encoding), 'TFileIO.CheckBOM: Encoding is nil'); Preamble := Encoding.GetPreamble; if Length(Preamble) = 0 then Exit(False); if Stream.Size < Length(Preamble) then Exit(False); OldPos := Stream.Position; SetLength(Bytes, Length(Preamble)); Stream.Position := 0; Stream.ReadBuffer(Pointer(Bytes)^, Length(Preamble)); Stream.Position := OldPos; Result := IsEqualBytes(Bytes, Preamble); end;
This method is in UIOUtils
UIOUtils
Implemented in commit 1ab44ec3
TFileIO.CheckBOM
has a bug where it returns true for zero length preambles instead of false. Fixed this incupola
as follows: