Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Learnpath: Fix HTML entity decoding in parent titles - refs BT#21767 #5566

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion public/main/lp/ScormApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -821,11 +821,13 @@ public static function switchItem($lpId, $user_id, $view_id, $current_item, $nex
$lpItemParents = $mylp->getCurrentItemParentNames($mylp->get_current_item_id());
$titleItemParents = '';
if (!empty($lpItemParents)) {
// Escape HTML entities
$escapedParents = array_map(function($parentTitle) {
return htmlspecialchars($parentTitle, ENT_QUOTES, 'UTF-8');
}, $lpItemParents);

$titleItemParents = json_encode($escapedParents);
// Encode JSON without escaping Unicode characters
$titleItemParents = json_encode($escapedParents, JSON_UNESCAPED_UNICODE | JSON_HEX_APOS | JSON_HEX_QUOT);
}
$return .= "olms.lms_lp_item_parents={$titleItemParents};";

Expand Down
19 changes: 17 additions & 2 deletions public/main/lp/scorm_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -1721,17 +1721,32 @@ function switch_item(current_item, next_item)
return true;
}

/**
* Decodes HTML entities in a string
* @param {string} str - The string with HTML entities
* @returns {string} - The decoded string
*/
function decodeHtmlEntities(str) {
var txt = document.createElement("textarea");
txt.innerHTML = str;
return txt.value;
}

/**
* Updates the 'item-parent-names' div with the titles of the current item's parents.
*/
function updateItemParentNames() {
var parentNamesContainer = document.getElementById('item-parent-names');
if (parentNamesContainer) {
parentNamesContainer.innerHTML = '';
olms.lms_lp_item_parents.forEach(function(parentTitle) {

// Ensure olms.lms_lp_item_parents is an array
var parentNames = Array.isArray(olms.lms_lp_item_parents) ? olms.lms_lp_item_parents : [];

parentNames.forEach(function(parentTitle) {
var h3 = document.createElement('h3');
h3.className = 'text-h5';
h3.textContent = parentTitle;
h3.textContent = decodeHtmlEntities(parentTitle);
parentNamesContainer.appendChild(h3);
});
}
Expand Down
Loading