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

MoodleNet API does not completely convert description to plaintext

XMLWordPrintable

    • MOODLE_402_STABLE
    • MOODLE_402_STABLE
    • MDL-77959-master
    • Hide

      Covered by PHPUnit

      Environment setup

      1. Setup an account on the MoodleNet Prototype site if you do not already have one (or ping Mick or Huong for account information if you cannot create): https://mn3.prototype.moodle.net/ Note: once you create the account, you should receive a confirmation email which you need to use to activate your account, that email will probably go into your spam folder.
      2. Log in as admin.
      3. Navigate to Admin > Server > OAuth 2 services.
      4. Click on the "MoodleNet' button.
      5. Change the URL to "https://mn3.prototype.moodle.net/".
      6. Click Save changes.
      7. Navigate to "Site administration > General > MoodleNet > MoodleNet outbound settings".
      8. Change the MoodleNet OAuth2 provider to the created one.

      Manual test:

      1. Create a course
      2. Create an assignment and fill in the description with below (switching to the HTML/source view of the editor):

        <p>This is an example Moodle activity description.</p>
        <p>&nbsp;</p>
        <p>This is a formatted intro</p>
        <p>&nbsp;</p>
        <p>This thing has many lines.</p>
        <p>&nbsp;</p>
        <p>The last word of this sentence is in <strong>bold</strong></p>

      3. Navigate to the created assignment.
      4. Click More > Share to MoodleNet.
      5. Follow the steps.
      6. Verify that you will see " Saved to MoodleNet drafts ".
      7. Click the Go to MoodleNet drafts button.
      8. Verify that you can see the activity's description in plain text format.
      Show
      Covered by PHPUnit Environment setup Setup an account on the MoodleNet Prototype site if you do not already have one (or ping Mick or Huong for account information if you cannot create): https://mn3.prototype.moodle.net/ Note: once you create the account, you should receive a confirmation email which you need to use to activate your account, that email will probably go into your spam folder. Log in as admin. Navigate to Admin > Server > OAuth 2 services. Click on the "MoodleNet' button. Change the URL to " https://mn3.prototype.moodle.net/ ". Click Save changes. Navigate to "Site administration > General > MoodleNet > MoodleNet outbound settings". Change the MoodleNet OAuth2 provider to the created one. Manual test: Create a course Create an assignment and fill in the description with below (switching to the HTML/source view of the editor): <p>This is an example Moodle activity description.</p> <p>&nbsp;</p> <p>This is a formatted intro</p> <p>&nbsp;</p> <p>This thing has many lines.</p> <p>&nbsp;</p> <p>The last word of this sentence is in <strong>bold</strong></p> Navigate to the created assignment. Click More > Share to MoodleNet. Follow the steps. Verify that you will see " Saved to MoodleNet drafts ". Click the Go to MoodleNet drafts button. Verify that you can see the activity's description in plain text format.
    • 1
    • Team Hedgehog 2023 Sprint 1.4

      Currently we strip tags and convert to plaintext, however there are some cases which were discovered during testing aren't covered, such as:

      1. <br /> being introduced (I think this happens during the current conversion)
      2. non-tag HTML elements like:

        &nbsp;

      This can be confirmed by including the following in an activity's description, then checking the output of the activity_sender::share_activity (where it is setting $resourcedescription):

      <p>This is an example Moodle activity descdription.</p>
      <p>&nbsp;</p>
      <p>This is a formatted intro</p>
      <p>&nbsp;</p>
      <p>This thing has many lines.</p>
      <p>&nbsp;</p>
      <p>The last word of this sentence is in <strong>bold</strong></p>

      I would recommend while troubleshooting this, to copy the relevant cleaning code out to a page and hardcode the initial value, so you can tweak and refresh to see the value without having to go through the share process each time to test it (or output it to error_log).

      During my initial investigations, I have not yet found a complete (or elegant) solution, but did find:

      1. Putting html_entity_decode() inside the strip_tags() line removed the non-breaking spaces.
      2. Re-running strip-tags after converting to plaintext removed the extra breaks that were introduced, though this didn't seem like a great solution.
      3. There's still some line breaks included, which do work on the MoodleNet prototype, but I'm not sure if those are acceptable.

      During my own testing, this was the result I got to, it would be good if someone can check if there's a more elegant and complete solution (and verify if the newlines being introduced are "safe" for plaintext):

      // MoodleNet only accept plaintext descriptions.
      $resourcedescription = $DB->get_field($this->cminfo->modname, 'intro', ['id' => $this->cminfo->instance]);
      $resourcedescription = strip_tags(html_entity_decode($resourcedescription));
      $resourcedescription = format_text(
          $resourcedescription,
          FORMAT_PLAIN,
          ['context' => $coursecontext]
      );
      $resourcedescription = strip_tags($resourcedescription); 

        1. MDL-77959.png
          MDL-77959.png
          195 kB
        2. result.png
          result.png
          46 kB

            huongn@moodle.com Huong Nguyen
            michaelh Michael Hawkins
            Michael Hawkins Michael Hawkins
            Paul Holden Paul Holden
            Ron Carl Alfon Yu Ron Carl Alfon Yu
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 7 hours, 1 minute
                7h 1m

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