diff --git a/developer/src/tike/http/Keyman.Developer.System.HttpServer.App.pas b/developer/src/tike/http/Keyman.Developer.System.HttpServer.App.pas index b438efc916b..c934fc4163a 100644 --- a/developer/src/tike/http/Keyman.Developer.System.HttpServer.App.pas +++ b/developer/src/tike/http/Keyman.Developer.System.HttpServer.App.pas @@ -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; @@ -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 @@ -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; diff --git a/developer/src/tike/main/Keyman.Developer.System.ProjectOwningFile.pas b/developer/src/tike/main/Keyman.Developer.System.ProjectOwningFile.pas index b13a79e396c..e130adcf7fc 100644 --- a/developer/src/tike/main/Keyman.Developer.System.ProjectOwningFile.pas +++ b/developer/src/tike/main/Keyman.Developer.System.ProjectOwningFile.pas @@ -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; @@ -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