Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(developer): handle invalid project file when scanning for owner project 🍒 🏠 #11559

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ implementation
KeymanDeveloperOptions,
Keyman.Developer.System.Project.Project,
Keyman.Developer.System.Project.ProjectFile,
Keyman.Developer.System.Project.ProjectLoader,
Keyman.Developer.System.Project.WelcomeRenderer,
RedistFiles;

Expand Down Expand Up @@ -95,6 +96,7 @@ procedure TAppHttpResponder.RespondProject(doc: string; AContext: TIdContext;
procedure RespondProjectFile;
var
path: string;
p: TProject;
begin
if ARequestInfo.Params.IndexOfName('path') < 0 then
begin
Expand All @@ -113,12 +115,21 @@ procedure TAppHttpResponder.RespondProject(doc: string; AContext: TIdContext;
end;

// Transform the .kpj
with TProject.Create(ptUnknown, path, True) do
try
p := TProject.Create(ptUnknown, path, True);
except
on E:EProjectLoader do
begin
AResponseInfo.ResponseNo := 400;
AResponseInfo.ResponseText := 'Invalid project file: '+E.Message;
Exit;
end;
end;
try
AResponseInfo.ContentType := 'text/html; charset=UTF-8';
AResponseInfo.ContentText := Render;
AResponseInfo.ContentText := p.Render;
finally
Free;
p.Free;
end;
end;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ implementation
uses
System.SysUtils,

Keyman.Developer.System.Project.ProjectFile;
Keyman.Developer.System.Project.ProjectFile,
Keyman.Developer.System.Project.ProjectLoader;

function CheckOwnerProjectForFile(const project, filename: string): Boolean; forward;

Expand Down Expand Up @@ -71,7 +72,15 @@ function CheckOwnerProjectForFile(const project, filename: string): Boolean;
if SameFileName(project, filename) then
Exit(True);

p := TProject.Create(ptUnknown, project, True);
try
p := TProject.Create(ptUnknown, project, True);
except
on E:EProjectLoader do
begin
Result := False;
Exit;
end;
end;
try
Result := p.Files.IndexOfFileName(filename) >= 0;
finally
Expand Down
Loading