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

convert_urls_into_links www bug

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • 1.9.8, 2.0
    • 1.9.6
    • Filters
    • None
    • MOODLE_19_STABLE
    • MOODLE_19_STABLE, MOODLE_20_STABLE
    • Easy

      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);
      }

        1. bug20826.php
          2 kB
          Alan Trick
        2. testweblib.patch
          8 kB
          Andrew Davis
        3. weblib.patch
          4 kB
          Andrew Davis
        4. crazy_url_parser.patch.txt
          3 kB
          Eloy Lafuente (stronk7)
        5. testweblib2.patch
          9 kB
          Andrew Davis
        6. weblib2.patch
          4 kB
          Andrew Davis
        7. testweblib3.patch
          10 kB
          Andrew Davis
        8. weblib3.patch
          4 kB
          Andrew Davis

            andyjdavis Andrew Davis
            websterb Bruce Webster (Inactive)
            Nobody Nobody (Inactive)
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:

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