1

I have the following issue which I do not know how to resolve.

I have the following route on a api I am using :

'router' => [
        'routes' => [
            'test' => [
                'type'    => 'regex',
                'options' => [
                    'regex' => '/test(?<json>\/.*)?',
                    'defaults' => [
                        'controller' => TestController::class,
                        'action' => 'checkJson',
                        'json'   => '',
                    ],
                    'spec' => '/path%path%'
                ],
            ],
        ],
    ],

The idea is to catch all requests ending in a json string /test/[{"this is an example":1}]. This really works but the problem is, I would also like to accept when the input gets encoded like :

/test/%5B%7B%22this%20is%20an%20example%22%3A1%7D%5D

Any idea of how can I achieve what I am expecting ?

When the request is made using an encoded url, I get the following error in the browser :


Not Found

The requested URL /stock//test/[{"this is an example":1}] was not found on this server.

Any idea of how can I resolve this easily ?

Thank you

themazz
  • 1,107
  • 3
  • 10
  • 29
  • There is a way, to detect if part of your URL address is valid JSON string. Please check this atricle: http://stackoverflow.com/questions/2583472/regex-to-validate-json – VirCom May 06 '17 at 07:43
  • Code seems OK! May be you were trying with double slashes. Try with only single slash like `/stock/test/...` but not `/stock//test/...`. Because that is not satisfied/captured by your Regex pattern. – unclexo May 08 '17 at 17:08
  • Why are you sending using JSON strings as parameters? Wouldn't it be better/safer sending this as a POST request payload? – halfpastfour.am May 09 '17 at 14:08

0 Answers0