diff --git a/sources/MVCFramework.Commons.pas b/sources/MVCFramework.Commons.pas index aaef687eb..0b90f9ab7 100644 --- a/sources/MVCFramework.Commons.pas +++ b/sources/MVCFramework.Commons.pas @@ -113,7 +113,7 @@ TMVCConstants = record LAST_AUTHORIZATION_HEADER_VALUE = '__DMVC_LAST_AUTHORIZATION_HEADER_VALUE_'; SSE_RETRY_DEFAULT = 100; SSE_LAST_EVENT_ID = 'Last-Event-ID'; - URL_MAPPED_PARAMS_ALLOWED_CHARS = ' ������''"@\[\]\{\}\(\)\=;&#\.:!\_\/,%\w\d\x2D\x3A'; + URL_MAPPED_PARAMS_ALLOWED_CHARS = ' ������''"@\[\]\{\}\(\)\=;&#\.:!\_,%\w\d\x2D\x3A'; OneMiB = 1048576; OneKiB = 1024; DEFAULT_MAX_REQUEST_SIZE = OneMiB * 5; // 5 MiB diff --git a/unittests/general/Several/FrameworkTestsU.pas b/unittests/general/Several/FrameworkTestsU.pas index 929c2091f..1f7995d48 100644 --- a/unittests/general/Several/FrameworkTestsU.pas +++ b/unittests/general/Several/FrameworkTestsU.pas @@ -100,6 +100,8 @@ TTestRouting = class(TObject) [Test] procedure TestComplexRoutings; [Test] + procedure TestIssue338; + [Test] procedure TestProduceRoutings; [Test] procedure TestProduceRoutingsWithExplicitCharset; @@ -204,16 +206,13 @@ implementation MVCFramework.Serializer.Commons, MVCFramework.HMAC, System.Diagnostics, - {$IF CompilerVersion < 27} - +{$IF CompilerVersion < 27} Data.DBXJSON, - {$ELSE} - +{$ELSE} System.JSON, - {$ENDIF} - +{$ENDIF} TestServerControllerU, System.Classes, MVCFramework.DuckTyping, System.IOUtils, MVCFramework.SystemJSONUtils, IdGlobal; @@ -440,6 +439,36 @@ procedure TTestRouting.TestComplexRoutings; end; end; +procedure TTestRouting.TestIssue338; +var + Params: TMVCRequestParamsTable; + ResponseContentType: string; + ResponseContentEncoding: string; +begin + // https://github.com/danieleteti/delphimvcframework/issues/338 + Params := TMVCRequestParamsTable.Create; + try + Params.Clear; + Assert.isTrue(FRouter.ExecuteRouting('/projectid/pictures/imageuuid', httpGET, + 'text/plain', 'text/plain', FControllers, 'text/plain', TMVCMediaType.TEXT_PLAIN, Params, + ResponseContentType, ResponseContentEncoding)); + Assert.areEqual('GetImage', FRouter.MethodToCall.Name); + Assert.areEqual(2, Params.Count); + Assert.areEqual('projectid', Params['projectid']); + Assert.areEqual('imageuuid', Params['imageuuid']); + + Params.Clear; + Assert.isTrue(FRouter.ExecuteRouting('/projectid', httpGET, + 'text/plain', 'text/plain', FControllers, 'text/plain', TMVCMediaType.TEXT_PLAIN, Params, + ResponseContentType, ResponseContentEncoding)); + Assert.areEqual('GetProject', FRouter.MethodToCall.Name); + Assert.areEqual(1, Params.Count); + Assert.areEqual('projectid', Params['projectid']); + finally + Params.Free; + end; +end; + // procedure TTestMappers.TestDataSetToJSONArray; // var // ds: TClientDataSet; @@ -1139,8 +1168,8 @@ procedure TTestRouting.TestReservedIPs; // this test just tests the IP2Long implementation for I := low(RESERVED_IPS) to high(RESERVED_IPS) do begin - Assert.AreEqual(IPv4ToUInt32(RESERVED_IPS[I][1]), IP2Long(RESERVED_IPS[I][1])); - Assert.AreEqual(IPv4ToUInt32(RESERVED_IPS[I][2]), IP2Long(RESERVED_IPS[I][2])); + Assert.areEqual(IPv4ToUInt32(RESERVED_IPS[I][1]), IP2Long(RESERVED_IPS[I][1])); + Assert.areEqual(IPv4ToUInt32(RESERVED_IPS[I][2]), IP2Long(RESERVED_IPS[I][2])); end; end; diff --git a/unittests/general/Several/LiveServerTestU.pas b/unittests/general/Several/LiveServerTestU.pas index 342987b1e..6718f9ed4 100644 --- a/unittests/general/Several/LiveServerTestU.pas +++ b/unittests/general/Several/LiveServerTestU.pas @@ -66,8 +66,8 @@ TServerTest = class(TBaseServerTest) public [Test] - [TestCase('request url /fault', '/fault')] - [TestCase('request url /fault2', '/fault2')] + [TestCase('request url /fault', '/exception/fault')] + [TestCase('request url /fault2', '/exception/fault2')] procedure TestControllerWithExceptionInCreate(const URLSegment: string); [Test] @@ -1537,7 +1537,7 @@ procedure TServerTest.TestTypedString1; lValues[3] := '"daniele teti"'; lValues[4] := '"daniele" "teti"'; lValues[5] := '"daniele" "teti"!'; - lValues[6] := ' _\"daniele" "teti"!/_ '; + lValues[6] := ' _\"daniele" "teti"!_ '; for s in lValues do begin diff --git a/unittests/general/Several/RESTAdapterTestsU.pas b/unittests/general/Several/RESTAdapterTestsU.pas index 970586da1..5fb862dbc 100644 --- a/unittests/general/Several/RESTAdapterTestsU.pas +++ b/unittests/general/Several/RESTAdapterTestsU.pas @@ -2,7 +2,7 @@ // // Delphi MVC Framework // -// Copyright (c) 2010-2017 Daniele Teti and the DMVCFramework Team +// Copyright (c) 2010-2020 Daniele Teti and the DMVCFramework Team // // https://github.com/danieleteti/delphimvcframework // @@ -69,7 +69,7 @@ interface [Headers('Accept', 'application/json')] [Headers('ContentType', 'application/json')] - [RESTResource(HttpGet, '/testconsumejson')] + [RESTResource(HttpGet, '/adapter/testconsumejson')] function HeadersApplicationJSON: TJSONValue; [Headers('Accept', 'text/plain')] @@ -79,7 +79,7 @@ interface [Headers('Accept', 'text/plain')] [Headers('ContentType', 'text/plain')] - [RESTResource(HttpGet, '/testconsumejson')] + [RESTResource(HttpGet, '/adapter/testconsumejson')] function ApplicationJSONWithTextPlainHeader: IRESTResponse; end; diff --git a/unittests/general/TestServer/TestServerControllerU.pas b/unittests/general/TestServer/TestServerControllerU.pas index 57fee35e0..8c3306dc7 100644 --- a/unittests/general/TestServer/TestServerControllerU.pas +++ b/unittests/general/TestServer/TestServerControllerU.pas @@ -97,7 +97,7 @@ TTestServerController = class(TMVCController) [MVCProduces('text/plain', 'utf-8')] procedure TestConsumesProducesText; - [MVCPath('/testconsumejson')] + [MVCPath('/adapter/testconsumejson')] [MVCHTTPMethod([httpGET])] [MVCConsumes('application/json')] [MVCProduces('application/json', 'utf-8')] @@ -221,6 +221,14 @@ TTestServerController = class(TMVCController) [MVCHTTPMethod([httpGET])] [MVCPath('/responses/nocontent')] procedure TestResponseNoContent; + + [MVCHTTPMethod([httpGET])] + [MVCPath('/($projectid)')] + procedure GetProject; + + [MVCHTTPMethod([httpGET])] + [MVCPath('/($projectid)/pictures/($imageuuid)')] + procedure GetImage; end; [MVCPath('/private')] @@ -235,7 +243,7 @@ TTestPrivateServerController = class(TMVCController) procedure OnlyRole2; end; - [MVCPath('/fault')] + [MVCPath('/exception/fault')] TTestFaultController = class(TMVCController) public [MVCPath] @@ -243,7 +251,7 @@ TTestFaultController = class(TMVCController) constructor Create; override; end; - [MVCPath('/fault2')] + [MVCPath('/exception/fault2')] TTestFault2Controller = class(TTestFaultController) public [MVCPath] @@ -340,6 +348,16 @@ procedure TTestServerController.GenerateCookies; end; +procedure TTestServerController.GetImage; +begin + // do nothing +end; + +procedure TTestServerController.GetProject; +begin + // do nothing +end; + procedure TTestServerController.Login; begin if Context.SessionStarted then