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

moodle_url does not support grotesquely stupid URLs (space in param name)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Minor Minor
    • None
    • 2.1
    • Libraries
    • None
    • MOODLE_21_STABLE
    • Hide

      I solved the problem in our custom code by using a plain string instead of a moodle_url to pass this information around.

      Show
      I solved the problem in our custom code by using a plain string instead of a moodle_url to pass this information around.
    • Hide

      Run code:

      $url = new moodle_url('http://example.org/?test+param=1');
      print_object($url->out(false));

      Expected result is

      http://example.org/?test+param=1

      or

      http://example.org/?test%20param=1

      Show
      Run code: $url = new moodle_url('http://example.org/?test+param=1'); print_object($url->out(false)); Expected result is http://example.org/?test+param=1 or http://example.org/?test%20param=1

      One of our internal systems (not developed internally, it's commercial software circa age of dinosaurs) uses really horrible URLs.

      One particular horrible thing about these URLs if that they contain spaces (escaped in URL as +) inside parameter names.

      In some parts of our moodle code, we accepted URL from user input (actually from an rss file) and tried to construct a moodle_url to parse it. This fails.

      $url = new moodle_url('http://example.org/?test+param=1');
      print_object($url->out(false));

      results in

      http://example.org/?test_param=1

      Note that the + has been changed to an _, whereas it should be either a + or %20. (You get the same result regardless of whether the original URL had + or %20. At least it's consistent.)

      I tracked this down in the code and it is caused by the PHP function parse_string which has this behaviour. Most likely this is because parse_string default behaviour is to set php variables which cannot have spaces in the name, however we are using it with the array parameter so it could work, but doesn't.

      Fixing this would seem to require either (a) doing a horrible regular expression prior to passing the query string to parse_string, or (b) replacing parse_string with custom code that does the job properly. Both seem quite risky and there are no unit tests for this aspect of moodle_url, so I decided not to try coding it just now, but am filing the bug just in case somebody else feels like it...

            moodle.com Moodle HQ
            quen Sam Marshall
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

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