Moodle

Database: Export of text field showing html entities (for comma - ,)

Details

  • Type: Bug Bug
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: 1.9.5, STABLE backlog
  • Fix Version/s: None
  • Labels:
    None
  • Difficulty:
    Easy
  • Affected Branches:
    MOODLE_19_STABLE

Description

I noticed when working on another export issue that I was seeing an html entity in the export which a user would not expect to see. This is easily enough fixed by creating an export_text_value function for the text field type (may also need to be done elsewhere - perhaps better to do in /mod/data/lib.php now that I think about it). I'm going to go ahead and replace the return $record->content with html_entity_decode($record->content). I'll attach a patch shortly. Attached are screen shots showing the broken and fixed exports. MDL-19864-whitespace.xls.png shows the text field Location with the html entity of , being displayed where database_export_fixed.png shows it with the html_entity_decode. I tried using the s function as suggested by David in the HQ chat but that did not work because the comma (&#44) is not considered an htmlspecialcharacter. Peace - Anthony

Activity

Hide
Anthony Borrow added a comment -

I began wondering why this has not come up before and realized that the html entities were added to the database because we had done a CVS import of the data exported from the database activity module on a demo site. I suspect that the export had converted the comma to the html entity which was then stored in the database. So this seems to be a case of just not making an assumption about the data in the database and whether it contains or does not contain html entities. Peace - Anthony

Show
Anthony Borrow added a comment - I began wondering why this has not come up before and realized that the html entities were added to the database because we had done a CVS import of the data exported from the database activity module on a demo site. I suspect that the export had converted the comma to the html entity which was then stored in the database. So this seems to be a case of just not making an assumption about the data in the database and whether it contains or does not contain html entities. Peace - Anthony
Hide
Anthony Borrow added a comment -

Going one step further, perhaps this indicates a slight weakness in the s function (not replacing the comma and possibly some other html entities. Would it makes sense to replace s with:

if ($strip) { return html_entity_decode(preg_replace("/&(#\d+);/i", "&$1;", htmlspecialchars(stripslashes_safe($var)))); } else { return html_entity_decode(preg_replace("/&(#\d+);/i", "&$1;", htmlspecialchars($var))); }
}

Since this would have implications for through out Moodle I would like to see further testing but wanted to propose the idea. The goal here is to handle cases where through some type of import, restore, or geeky user manually typing in an html entity that is stored in the database that it actually appear as a comma when being printed. Normally for displaying on a webpage this is accomplished with format_text; however, in the case of exporting data it seems this may be overlooked unless of course it is just me overlooking something. Peace - Anthony

Show
Anthony Borrow added a comment - Going one step further, perhaps this indicates a slight weakness in the s function (not replacing the comma and possibly some other html entities. Would it makes sense to replace s with: if ($strip) { return html_entity_decode(preg_replace("/&(#\d+);/i", "&$1;", htmlspecialchars(stripslashes_safe($var)))); } else { return html_entity_decode(preg_replace("/&(#\d+);/i", "&$1;", htmlspecialchars($var))); } } Since this would have implications for through out Moodle I would like to see further testing but wanted to propose the idea. The goal here is to handle cases where through some type of import, restore, or geeky user manually typing in an html entity that is stored in the database that it actually appear as a comma when being printed. Normally for displaying on a webpage this is accomplished with format_text; however, in the case of exporting data it seems this may be overlooked unless of course it is just me overlooking something. Peace - Anthony
Hide
Anthony Borrow added a comment -

re-assigning to Robert since he was going to help with the database activity module

Show
Anthony Borrow added a comment - re-assigning to Robert since he was going to help with the database activity module
Hide
Anthony Borrow added a comment -

re-assigning to moodle.com and adding fix version as stable backlog

Show
Anthony Borrow added a comment - re-assigning to moodle.com and adding fix version as stable backlog

People

Vote (1)
Watch (0)

Dates

  • Created:
    Updated: