Skip to content

Commit

Permalink
Merge pull request #10209 from keymanapp/fix/developer/10181-crash-lo…
Browse files Browse the repository at this point in the history
…ading-ldml-xml

fix(developer): crash loading a project when referenced .xml is missing
  • Loading branch information
mcdurdin authored Dec 11, 2023
2 parents e59ef93 + 22b7f5b commit 2fab459
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,21 @@ class function TxmlLdmlProjectFile.IsFileTypeSupported(const Filename: string):
var
ss: TStringStream;
begin
// Look for DTD in plain text as an adequate heuristic
ss := TStringStream.Create('', TEncoding.UTF8);
try
ss.LoadFromFile(Filename);
Result := ss.DataString.IndexOf('ldmlKeyboard3.dtd') > 0;
finally
ss.Free;
// Look for DTD in plain text as an adequate heuristic
ss := TStringStream.Create('', TEncoding.UTF8);
try
ss.LoadFromFile(Filename);
Result := ss.DataString.IndexOf('ldmlKeyboard3.dtd') > 0;
finally
ss.Free;
end;
except
// If we can't read the file, e.g. it is missing, or is not in UTF-8, or
// is locked, etc., then we'll just say it's not an XML LDML keyboard
// file. Yes, this is a catch-all exception handler, but that should be
// permissible for this scenario
Exit(False);
end;
end;

Expand Down

0 comments on commit 2fab459

Please sign in to comment.