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

getValidationScript in formslib.php has a wrong regexp

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.7.5, 2.8.3
    • Fix Version/s: 2.7.6, 2.8.4
    • Component/s: Forms Library
    • Labels:
    • Testing Instructions:
      Hide
      1. Turn on Admin -> Security -> Site policies -> Strict validation of required fields
      2. Set your editor to be TinyMCE
      3. Go and create a Description 'question' (or anything else with a required HTML field.)
      4. Enter any question name.
      5. Use the HTML button (<>) to set the Question text to <p><strong>&#160;</strong></p>. (That's a bold non-breaking space.)
      6. Try to submit the form.
      7. Verify that the client-side Java-Script prevents you from submitting.
      8. Chang the Question text to a single b (which is really HTML '<p>b</p>'.)
      9. Try to submit the form.
      10. Verify that works.
      Show
      Turn on Admin -> Security -> Site policies -> Strict validation of required fields Set your editor to be TinyMCE Go and create a Description 'question' (or anything else with a required HTML field.) Enter any question name. Use the HTML button (<>) to set the Question text to <p><strong>&#160;</strong></p>. (That's a bold non-breaking space.) Try to submit the form. Verify that the client-side Java-Script prevents you from submitting. Chang the Question text to a single b (which is really HTML '<p>b</p>'.) Try to submit the form. Verify that works.
    • Affected Branches:
      MOODLE_27_STABLE, MOODLE_28_STABLE
    • Fixed Branches:
      MOODLE_27_STABLE, MOODLE_28_STABLE
    • Pull from Repository:
    • Pull Master Branch:

      Description

      Steps to reproduce.

      1. Turn on Admin -> Security -> Site policies -> Strict validation of required fields
      2. Set your editor to be TinyMCE
      3. Go and create a Multiple choice question (or anything else with a required HTML field.)
      4. Enter a question name.
      5. Type b into the Question text.
      6. Try to submit the form.

      Actual result:

      The form does not submit. Client-side JS marks the Question text as "You must supply a value here."

      Expected result:

      The form submits. b is not blank. (Of course the value of the field is actually '<p>b</p>'.

      The problem is the regex in getValidationScript in lib/formslib.php. It is:

      return array('', "

      {jsVar}

      .replace(/(<[^img|hr|canvas]>)| |\s/ig, '') == ''");

      That regex, added by MDL-28987, does not do what was intended. I will fix it.

        Attachments

          Activity

            People

            Assignee:
            timhunt Tim Hunt
            Reporter:
            timhunt Tim Hunt
            Peer reviewer:
            Rajesh Taneja
            Integrator:
            Andrew Nicols
            Tester:
            John Okely
            Participants:
            Component watchers:
            Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Fix Release Date:
              9/Mar/15