Moodle
  1. Moodle
  2. MDL-30595

preg_replace_callback range out of order in mod/url /locallib in PHP 5.2.x

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 2.0.6
    • Fix Version/s: 2.0.7
    • Component/s: Resource
    • Labels:
    • Testing Instructions:
      Hide

      1/ find server with php 5.2.x
      2/ try adding new url module instance

      Show
      1/ find server with php 5.2.x 2/ try adding new url module instance
    • Affected Branches:
      MOODLE_20_STABLE
    • Fixed Branches:
      MOODLE_20_STABLE
    • Pull from Repository:
    • Rank:
      33394

      Description

      After upgrade to Moodle 2.0.6, mod/url des not opens up anymore the original location. With debugging, the following message is displayed:

      Warning: preg_replace_callback() [function.preg-replace-callback]: Compilation failed: range out of order in character class at offset 39 in /your/path/to/moodle/mod/url/locallib.php on line 95

      To reproduce:

      • on a 2.0.6 site, with Multimedia and Glossary filter on, turn debugging on
      • add an URL resource pointing to an external link.
      • configure the resource "view" option to "open" or "popup"
      • click "save and view". The Warning in displayed, the url is not open in the popup, and the link is not printed when resource "view" option is set to "open"

        Issue Links

          Activity

          Hide
          Michael de Raadt added a comment -

          This appears to duplicate the linked issue. Could you check your PHP version and see if this problem still exists?

          Show
          Michael de Raadt added a comment - This appears to duplicate the linked issue. Could you check your PHP version and see if this problem still exists?
          Hide
          Andrea Bicciolo added a comment -

          Michael,

          php version in the failing Moodle setups is 5.2.17, that should be OK as it is > 5.2.8.

          According to Server->Environment:

          php - version 5.2.8 is required and you are running 5.2.17.0.0 - OK

          And yes, the problem still exits.Please let me know if you want me give you some samples.

          Show
          Andrea Bicciolo added a comment - Michael, php version in the failing Moodle setups is 5.2.17, that should be OK as it is > 5.2.8. According to Server->Environment: php - version 5.2.8 is required and you are running 5.2.17.0.0 - OK And yes, the problem still exits.Please let me know if you want me give you some samples.
          Hide
          Petr Škoda added a comment - - edited

          hello, I would need the exact URL that creates this problem.

          the error is somewhere in

          $allowed = "a-zA-Z0-9".preg_quote(';/?:@=&$_.+!*(),-#%', '/');
          $fullurl = preg_replace_callback("/[^$allowed]/", 'url_filter_callback', $fullurl);
          

          preg_quote() docs says that since 5.3 the - char is properly quoted, could you please try to move the - to the end of the string? that could help...

          $allowed = "a-zA-Z0-9".preg_quote(';/?:@=&$_.+!*(),#%-', '/');
          Show
          Petr Škoda added a comment - - edited hello, I would need the exact URL that creates this problem. the error is somewhere in $allowed = "a-zA-Z0-9" .preg_quote(';/?:@=&$_.+!*(),-#%', '/'); $fullurl = preg_replace_callback( "/[^$allowed]/" , 'url_filter_callback', $fullurl); preg_quote() docs says that since 5.3 the - char is properly quoted, could you please try to move the - to the end of the string? that could help... $allowed = "a-zA-Z0-9" .preg_quote(';/?:@=&$_.+!*(),#%-', '/');
          Hide
          Petr Škoda added a comment -

          In any case I would strongly recommend using PHP 5.3.x on all production servers especially for larger sites.

          Show
          Petr Škoda added a comment - In any case I would strongly recommend using PHP 5.3.x on all production servers especially for larger sites.
          Hide
          Andrea Bicciolo added a comment -

          Hi Petr,

          sent you 3 samples of failing URLs.

          Show
          Andrea Bicciolo added a comment - Hi Petr, sent you 3 samples of failing URLs.
          Show
          Petr Škoda added a comment - please try this: https://github.com/skodak/moodle/compare/MOODLE_20_STABLE...w50_MDL-30595_m20_regex
          Hide
          Rosario Carcò added a comment -

          Only for information, as Petr asked me to try the above patch: I have SUSE SLES 11 SP1, with: PHP version 5.2.8 is required and you are running 5.2.14

          Show
          Rosario Carcò added a comment - Only for information, as Petr asked me to try the above patch: I have SUSE SLES 11 SP1, with: PHP version 5.2.8 is required and you are running 5.2.14
          Hide
          Petr Škoda added a comment -

          did it work?

          Show
          Petr Škoda added a comment - did it work?
          Hide
          Rosario Carcò added a comment -

          OK, that patch works for me! Thanks a lot.

          Show
          Rosario Carcò added a comment - OK, that patch works for me! Thanks a lot.
          Hide
          Petr Škoda added a comment -

          thanks for the testing!!

          Show
          Petr Škoda added a comment - thanks for the testing!!
          Hide
          Petr Škoda added a comment -

          to integrators: it is not necessary to change anything in 2.1 and above because it requries php 5.3 which quotes the - character in preg_quote()

          Show
          Petr Škoda added a comment - to integrators: it is not necessary to change anything in 2.1 and above because it requries php 5.3 which quotes the - character in preg_quote()
          Hide
          Andrea Bicciolo added a comment -

          Hi Petr,
          tried your patch with the same sample URLs sent for your tests, and they worked.

          Show
          Andrea Bicciolo added a comment - Hi Petr, tried your patch with the same sample URLs sent for your tests, and they worked.
          Hide
          Eloy Lafuente (stronk7) added a comment -

          Integrated, thanks!

          Show
          Eloy Lafuente (stronk7) added a comment - Integrated, thanks!
          Hide
          Sam Hemelryk added a comment -

          Passing testing as Andrea has previously tested this patch. Thanks Andrea!

          Show
          Sam Hemelryk added a comment - Passing testing as Andrea has previously tested this patch. Thanks Andrea!
          Hide
          Eloy Lafuente (stronk7) added a comment -

          Yes, you did it!

          Now your code is part of the best weeklies released ever, many thanks!

          Closing, ciao

          Show
          Eloy Lafuente (stronk7) added a comment - Yes, you did it! Now your code is part of the best weeklies released ever, many thanks! Closing, ciao

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: