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

getValidationScript in formslib.php has a wrong regexp

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.7.5, 2.8.3
    • 2.7.6, 2.8.4
    • Forms Library
    • MOODLE_27_STABLE, MOODLE_28_STABLE
    • MOODLE_27_STABLE, MOODLE_28_STABLE
    • 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.

    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

            timhunt Tim Hunt
            timhunt Tim Hunt
            Rajesh Taneja Rajesh Taneja
            Andrew Lyons Andrew Lyons
            John Okely John Okely
            Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Sujith Haridasan
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              9/Mar/15