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

Escape special regex characters before applying perl compatible regex substitution of field names for database activity's advanced search

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.9, 1.9.1
    • Fix Version/s: 1.9.2
    • Labels:
      None
    • Database:
      Any
    • Affected Branches:
      MOODLE_19_STABLE
    • Fixed Branches:
      MOODLE_19_STABLE

      Description

      When the name of a field contains a special perl-compatible regex character such as "/" or "+", the advanced search page will not create an input box for such fields. In the attached screenshot this is shown for the field with the name "A/X". The same field type (text) with the name "AX" works fine, but "A/X" or "A + X" does not work.

        Gliffy Diagrams

          Attachments

            Activity

            Hide
            roal Robert Allerstorfer added a comment -

            The attached patch fixes this bug.

            The solution was to escape the chars / and + with \ before applying the perl regex substitution.

            Show
            roal Robert Allerstorfer added a comment - The attached patch fixes this bug. The solution was to escape the chars / and + with \ before applying the perl regex substitution.
            Hide
            stronk7 Eloy Lafuente (stronk7) added a comment -

            Hi Robert,

            shouldn't be preg_quote() instead of addcslashes? That's the natural function to escape characters with "meaning" in regular expressions AFAIK.

            Ciao

            Show
            stronk7 Eloy Lafuente (stronk7) added a comment - Hi Robert, shouldn't be preg_quote() instead of addcslashes? That's the natural function to escape characters with "meaning" in regular expressions AFAIK. Ciao
            Hide
            stronk7 Eloy Lafuente (stronk7) added a comment -

            Also,

            feel free to assign yourself database bugs (I think that if you add me or Petr or Martin for confirmation/vote is a good strategy). Ususally one +1 is required to go to HEAD and +2 for stable versions.

            Thanks and ciao

            Show
            stronk7 Eloy Lafuente (stronk7) added a comment - Also, feel free to assign yourself database bugs (I think that if you add me or Petr or Martin for confirmation/vote is a good strategy). Ususally one +1 is required to go to HEAD and +2 for stable versions. Thanks and ciao
            Hide
            roal Robert Allerstorfer added a comment -

            Hi Eloy,

            yes, preg_quote() is the better solution. Then I think we should use
            $fieldname = preg_quote($fieldname, '/');

            And thanks for explaing the usual committing policy

            Show
            roal Robert Allerstorfer added a comment - Hi Eloy, yes, preg_quote() is the better solution. Then I think we should use $fieldname = preg_quote($fieldname, '/'); And thanks for explaing the usual committing policy
            Hide
            roal Robert Allerstorfer added a comment -

            OK, here is the new patch (MDL-14816_20080518.patch) using preg_quote($fieldname, '/'). It works fine - I have tested it successfully.

            Show
            roal Robert Allerstorfer added a comment - OK, here is the new patch ( MDL-14816 _20080518.patch) using preg_quote($fieldname, '/'). It works fine - I have tested it successfully.
            Hide
            roal Robert Allerstorfer added a comment -

            Eloy,

            as you suggested, I have re-assigned this issue to me. The solution is clear, so I'm planning to commit my patch soon unless there is feedback against it.

            Thanks for your attention.

            Show
            roal Robert Allerstorfer added a comment - Eloy, as you suggested, I have re-assigned this issue to me. The solution is clear, so I'm planning to commit my patch soon unless there is feedback against it. Thanks for your attention.
            Hide
            dongsheng Dongsheng Cai added a comment -

            Verified, thanks, Robert.

            Show
            dongsheng Dongsheng Cai added a comment - Verified, thanks, Robert.

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  11/Jul/08