View Issue Details

IDProjectCategoryView StatusLast Update
0038607FPCPatchpublic2021-03-09 14:59
ReporterCudaText man Assigned ToMichael Van Canneyt  
PrioritynormalSeverityminorReproducibilityN/A
Status closedResolutionfixed 
Product Version3.3.1 
Fixed in Version3.2.1 
Summary0038607: JsonConf: skip UTF8 BOM on reading file
DescriptionPatch allows to read JSON files with UTF8 BOM marker.
I tested this on demo, attached demo with included JSON lib with my changes.
Changes --

procedure SkipStreamBOM(S: TStream);
Var
  OldPos : integer;
  Header : array[0..3] of byte;
begin
  OldPos := S.Position;
  FillChar(Header, SizeOf(Header), 0);
  if S.Read(Header, 3) = 3 then
    if (Header[0]=$EF) and (Header[1]=$BB) and (Header[2]=$BF) then
      exit;
  S.Position := OldPos;
end;

procedure TJSONConfig.LoadFromStream(S: TStream);

Var
  P : TJSONParser;
  J : TJSONData;

begin
  SkipStreamBOM(S);
  P:=TJSONParser.Create(S,FJSONOptions);
  try
....

       
TagsNo tags attached.
Fixed in Revision48926
FPCOldBugId
FPCTarget4.0.0
Attached Files

Activities

CudaText man

2021-03-09 10:30

reporter  

tst-json-and-utf8bom.zip (53,186 bytes)

Michael Van Canneyt

2021-03-09 12:58

administrator   ~0129525

Thank you for the patch.

I added this at a higher level:
I introduced a JoBOMCheck option in the JSON options. It's set by default in jsonconf component.

Please check and close if OK.

Benito van der Zander

2021-03-09 14:07

reporter   ~0129526

What if the stream is not seekable?

Michael Van Canneyt

2021-03-09 14:59

administrator   ~0129529

That is why it is optional and not enabled by default.

Issue History

Date Modified Username Field Change
2021-03-09 10:30 CudaText man New Issue
2021-03-09 10:30 CudaText man File Added: tst-json-and-utf8bom.zip
2021-03-09 12:58 Michael Van Canneyt Assigned To => Michael Van Canneyt
2021-03-09 12:58 Michael Van Canneyt Status new => resolved
2021-03-09 12:58 Michael Van Canneyt Resolution open => fixed
2021-03-09 12:58 Michael Van Canneyt Fixed in Version => 3.2.1
2021-03-09 12:58 Michael Van Canneyt Fixed in Revision => 48926
2021-03-09 12:58 Michael Van Canneyt FPCTarget => 4.0.0
2021-03-09 12:58 Michael Van Canneyt Note Added: 0129525
2021-03-09 14:07 Benito van der Zander Note Added: 0129526
2021-03-09 14:40 CudaText man Status resolved => closed
2021-03-09 14:59 Michael Van Canneyt Note Added: 0129529