Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-85188

Multiple query parameters not forwarded correctly in shim

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • 5.0
    • General
    • MOODLE_500_STABLE

      I've been investigating converting pages to the new routed page controller system introduced in MDL-82565 (which is fantastic!) and have discovered an odd issue with the shim feature.

      What seems to be happening is that, where there are multiple query parameters defined, the ampersands between them are being HTML encoded into "&" which means that all but the first one aren't available to the page controller being forwarded to. For example "course/query_test.php?param1=11&param2=59&param3=0" is forwarded to "course/query_test?param1=11&param2=59&param3=0" instead of "course/query_test?param1=11&param2=59&param3=0".

      To reproduce:

      Create course/query_test.php:

      <?php
      require_once __DIR__ . '/../r.php';
      

      Create course/classes/route/controller/query_test.php:

      <?php
       
      namespace core_course\route\controller;
       
      use core\param;
      use core\router\route;
      use core\router\route_controller;
      use core\router\schema\parameters\query_parameter;
      use Psr\Http\Message\ResponseInterface;
      use Psr\Http\Message\ServerRequestInterface;
       
      class query_test {
       
          use route_controller;
       
          #[route(
              path: '/query_test',
              method: 'GET',
              queryparams: [
                  new query_parameter(name: 'param1', type: param::INT, required: true),
                  new query_parameter(name: 'param2', type: param::INT, required: true),
                  new query_parameter(name: 'param3', type: param::INT, required: true),
              ]
          )]
          public function query_test(ServerRequestInterface $request, ResponseInterface $response) {
              $parameters = $request->getQueryParams();
              $response->getBody()->write($parameters['param1']);
              $response->getBody()->write($parameters['param2']);
              $response->getBody()->write($parameters['param3']);
          }
       
      }
      

      Add to \core_course\route\shim\course_routes this method:

      #[route(
              path: '/query_test.php',
              method: 'GET',
              queryparams: [
                  new query_parameter(name: 'param1', type: param::INT, required: true),
                  new query_parameter(name: 'param2', type: param::INT, required: true),
                  new query_parameter(name: 'param3', type: param::INT, required: true),
              ]
          )]
          function query_test(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
          {
              return self::redirect_to_callable($request, $response, [\core_course\route\controller\query_test::class, 'query_test']);
          }
      
      

      Purge caches and whatever needs to be done to make the route available.

      Browse to /course/query_test.php?param1=11&param2=59&param3=0

      You will be redirected to /course/query_test.php?param1=11&amp;param2=59&amp;param3=0 and see an error about required parameters not being set.

            Unassigned Unassigned
            maherne Michael Aherne
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.