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

MBS-8802: Fix handling of title strings #45

Merged
merged 7 commits into from
Mar 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
2 changes: 1 addition & 1 deletion amd/build/card.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion amd/build/card.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion amd/build/column.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion amd/build/column.min.js.map

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion amd/src/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,11 @@ export default class extends KanbanComponent {
}
// Update title (also in modals).
if (element.title !== undefined) {
this.getElement(selectors.INPLACEEDITABLE).setAttribute('data-value', element.title);
// For Moodle inplace editing title is once needed plain and once with html entities encoded.
// This avoids double encoding of html entities as the value of "data-value" is exactly what is shown
// in the input field when clicking on the inplace editable.
let doc = new DOMParser().parseFromString(element.title, 'text/html');
this.getElement(selectors.INPLACEEDITABLE).setAttribute('data-value', doc.documentElement.textContent);
this.getElement(selectors.INPLACEEDITABLE).querySelector('a').innerHTML = element.title;
this.getElement(selectors.DESCRIPTIONMODALTITLE).innerHTML = element.title;
this.getElement(selectors.DISCUSSIONMODALTITLE).innerHTML = element.title;
Expand Down
6 changes: 5 additions & 1 deletion amd/src/column.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,11 @@ export default class extends KanbanComponent {
}
// Update data for inplace editing if title was updated (this is important if title was modified by another user).
if (element.title !== undefined) {
this.getElement(selectors.INPLACEEDITABLE).setAttribute('data-value', element.title);
// For Moodle inplace editing title is once needed plain and once with html entities encoded.
// This avoids double encoding of html entities as the value of "data-value" is exactly what is shown
// in the input field when clicking on the inplace editable.
let doc = new DOMParser().parseFromString(element.title, 'text/html');
this.getElement(selectors.INPLACEEDITABLE).setAttribute('data-value', doc.documentElement.textContent);
this.getElement(selectors.INPLACEEDITABLE).querySelector('a').innerHTML = element.title;
}
// Only autohide option is relevant for the frontend for now. autoclose option is handled by the backend.
Expand Down
4 changes: 2 additions & 2 deletions classes/boardmanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ public function update_card(int $cardid, array $data): void {
];
// Do some extra sanitizing.
if (isset($data['title'])) {
$data['title'] = clean_param($data['title'], PARAM_TEXT);
$data['title'] = s($data['title']);
}
if (isset($data['description'])) {
$data['description'] = clean_param($data['description'], PARAM_CLEANHTML);
Expand Down Expand Up @@ -946,7 +946,7 @@ public function update_column(int $columnid, array $data): void {
'autohide' => $data['autohide'],
];
if (isset($data['title'])) {
$data['title'] = clean_param($data['title'], PARAM_TEXT);
$data['title'] = s($data['title']);
}
$columndata = [
'id' => $columnid,
Expand Down
1 change: 1 addition & 0 deletions classes/form/edit_card_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public function set_data_for_dynamic_submission(): void {
$id = $this->optional_param('id', null, PARAM_INT);
$card = $DB->get_record('kanban_card', ['id' => $id]);
$options = json_decode($card->options);
$card->title = html_entity_decode($card->title, ENT_COMPAT, 'UTF-8');
$card->cmid = $this->optional_param('cmid', null, PARAM_INT);
$card->boardid = $card->kanban_board;
$card->assignees = $DB->get_fieldset_select('kanban_assignee', 'userid', 'kanban_card = :cardid', ['cardid' => $id]);
Expand Down
1 change: 1 addition & 0 deletions classes/form/edit_column_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public function set_data_for_dynamic_submission(): void {
$id = $this->optional_param('id', null, PARAM_INT);
$column = $DB->get_record('kanban_column', ['id' => $id]);
$column->cmid = $this->optional_param('cmid', null, PARAM_INT);
$column->title = html_entity_decode($column->title, ENT_COMPAT, 'UTF-8');
$column->boardid = $column->kanban_board;
$options = json_decode($column->options);
$column->autoclose = $options->autoclose;
Expand Down
8 changes: 3 additions & 5 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,15 @@ function kanban_inplace_editable($itemtype, $itemid, $newvalue) {

\mod_kanban\helper::check_permissions_for_user_or_group($boardmanager->get_board(), $context, $boardmanager->get_cminfo());

$newtitle = clean_param($newvalue, PARAM_TEXT);

if ($itemtype == 'card') {
$boardmanager->update_card($itemid, ['title' => $newtitle]);
$boardmanager->update_card($itemid, ['title' => $newvalue]);
}

if ($itemtype == 'column') {
$boardmanager->update_column($itemid, ['title' => $newtitle]);
$boardmanager->update_column($itemid, ['title' => $newvalue]);
}

return new \core\output\inplace_editable('mod_kanban', $itemtype, $itemid, true, $newtitle, $newtitle, null, '');
return new \core\output\inplace_editable('mod_kanban', $itemtype, $itemid, true, s($newvalue), $newvalue, null, '');
PhMemmel marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
4 changes: 2 additions & 2 deletions templates/card.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
<div class="card-body">
<div class="mod_kanban_card_title card-title">
<span class="inplaceeditable inplaceeditable-text"{{#canedit}}{{^completed}} data-inplaceeditable="1" data-component="mod_kanban" data-itemtype="card" data-itemid="{{id}}"
data-value="{{title}}" data-type="text"{{/completed}}{{/canedit}}>
data-value="{{{title}}}" data-type="text"{{/completed}}{{/canedit}}>
<a href="#" class="quickeditlink aalink"{{#canedit}}{{^completed}} data-inplaceeditablelink="1"{{/completed}}{{/canedit}}>
{{title}}
{{{title}}}
</a>
</span>
</div>
Expand Down
4 changes: 2 additions & 2 deletions templates/column.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
<li class="mod_kanban_column col card{{#autohide}} mod_kanban_autohide{{/autohide}} {{#locked}}mod_kanban_locked_column{{/locked}}" id="mod_kanban_column-{{id}}" data-id="{{id}}">
<h5 class="mod_kanban_column_title card-title">
<span class="inplaceeditable inplaceeditable-text"{{#managecolumns}} {{^locked}}data-inplaceeditable="1" {{/locked}}data-component="mod_kanban" data-itemtype="column" data-itemid="{{id}}"
data-value="{{title}}" data-type="text"{{/managecolumns}}>
data-value="{{{title}}}" data-type="text"{{/managecolumns}}>
<a href="#" class="quickeditlink aalink"{{#managecolumns}} data-inplaceeditablelink="1"{{/managecolumns}}>
{{title}}
{{{title}}}
</a>
</span>
</h5>
Expand Down
Loading