Skip to content

Commit

Permalink
Merge pull request #11558 from keymanapp/fix/developer/11557-invalid-…
Browse files Browse the repository at this point in the history
…project-file-at-launch

fix(developer): handle invalid project file when scanning for owner project
  • Loading branch information
mcdurdin authored May 30, 2024
2 parents 8495406 + 15acd71 commit e5e21e7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
17 changes: 14 additions & 3 deletions developer/src/tike/http/Keyman.Developer.System.HttpServer.App.pas
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

0 comments on commit e5e21e7

Please sign in to comment.