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

convert_urls_into_links www bug

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.9.6
    • Fix Version/s: 1.9.8, 2.0
    • Component/s: Filters
    • Labels:
      None
    • Difficulty:
      Easy
    • Affected Branches:
      MOODLE_19_STABLE
    • Fixed Branches:
      MOODLE_19_STABLE, MOODLE_20_STABLE

      Description

      The convert_urls_into_links function in lib/weblib.php has bad regular expressions.
      The regex used sucks up anything after the domain until it hits a space.

      Something like
      <p>text www.example.com</p> text
      gets completely trashed, and produces
      <p>text <a href="http://www.apple.com</p" target="_blank">www.example.com</p</a>> text
      Which in effect makes the rest of the content vanish.

      I changed the regex to fix it.
      I just rewrote the regexes, but it's much better than what was there... I only mess with http(s):// or www urls with at least one period in the host string.
      Also no longer using the deprecated ereg function. See MDL-20821

      function convert_urls_into_links(&$text) {
      /// Make lone URLs into links. eg http://moodle.com/
      $text = preg_replace("!([[:space:]]|^|(|[)(https?)://([[:alnum:]]\.[[:alnum:].;_%#?/&=][[:alnum:]])!i",
      "
      1<a href=\"\\2://\\3\" target=\"_blank\">\\2://
      3</a>", $text);

      /// eg www.moodle.com
      $text = preg_replace("!([[:space:]]|^|(|[)www\.([[:alnum:]]\.[[:alnum:].;_%#?/&=][[:alnum:]])!i",
      "
      1<a href=\"http://www.\\2\" target=\"_blank\">www.
      2</a>", $text);
      }

        Gliffy Diagrams

          Attachments

          1. bug20826.php
            2 kB
          2. crazy_url_parser.patch.txt
            3 kB
          3. testweblib.patch
            8 kB
          4. testweblib2.patch
            9 kB
          5. testweblib3.patch
            10 kB
          6. weblib.patch
            4 kB
          7. weblib2.patch
            4 kB
          8. weblib3.patch
            4 kB

            Issue Links

              Activity

                People

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

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Fix Release Date:
                    25/Mar/10