-
Bug
-
Resolution: Fixed
-
Minor
-
3.6.3
-
MOODLE_36_STABLE
-
MOODLE_38_STABLE
-
MDL-65183-MOODLE-master -
There are a few ways to get newline characters (\r\n) saved in the database as a label or activity name. When loading the dashboard (/my/ page), the timeline block goes to display the activity list but it does not do any validation of the data it finds for the activity names, and an ajax JSON parse error will display as shown in the screenshot (block_timeline_error.png):
JSON.parse: bad control character in string literal at line 1 column 30 of the JSON data |
Simple way to get this error on a clean moodle 3.6:
- Set up a test course, and enrol your user into it so that that courses activities will show up on the dashboard.
- In the test course, create a label. As shown in the screenshot (create_label.png), enable activity completion and set it to a date after today, and just copy and paste the following in for the label text in HTML mode (not rich text editor):
<h4>test heading</h4>
<p>then a paragraph</p>
- You will now see the error in the timeline block on a reload of the dashboard.
If you don't see the error, verify in the database that you have newline characters inserted into the mdl_event table for that label (see screenshot newline_in_db.png), and purge caches. I found that the caching is quite aggressive and would have to disable activity completion, save, and then re-enable and save again for changes to be seen on the dashboard. Attached is also a picture from the network console tab in the browser that shows the newline characters. Interestingly, the browser parses the JSON correctly, but moodle doesn't (network_tab_response.png).
You can also get newline characters to save to the database when adding a newline character in rich text editing mode, and that also causes the error.
We probably don't care that these newline characters are inserted in the database, but there should be extra validation in the timeline block when it goes to parse and display the data that is fetched.
We probably want to do some encoding on the newline characters, which means that it can display in ascii characters in the json, rather than being displayed as a new line. Might need to do decoding on the other end too. Looks like there is some encoding that can happen in the external_format_text method in lib/externallib.php, looking at line 958:
* newlines : If true then lines newline breaks will be converted to HTML newline breaks. Default true. |
- caused a regression
-
MDL-70342 block_timeline: Get rid of double quotes around activity name and course name
- Closed