Skip to content

Commit

Permalink
fix: added missing conversion to HTML entities
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Mar 10, 2023
1 parent d773df9 commit 7f0f921
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
21 changes: 18 additions & 3 deletions phpmyfaq/admin/stopwords.php
Expand Up @@ -106,10 +106,10 @@ function buildStopWordsHTML(data) {
}

// id attribute is of the format stopword_<id>_<lang>
elem_id = buildStopWordInputElemId(data[i].id, data[i].lang);
elem_id = buildStopWordInputElemId(data[i].id, escape(data[i].lang));

html += '<td>';
html += buildStopWordInputElement(elem_id, data[i].stopword);
html += buildStopWordInputElement(elem_id, escape(data[i].stopword));
html += '</td>';

if (i % maxCols === maxCols - 1) {
Expand All @@ -136,7 +136,7 @@ function buildStopWordInputElement(elementId, stopword) {
elementId = elementId || buildStopWordInputElemId();
stopword = stopword || '';
const attrs = 'onblur="saveStopWord(this.id)" onkeydown="saveStopWordHandleEnter(this.id, event)" onfocus="saveOldValue(this.id)"';
return '<input class="form-control form-control-sm" id="' + elementId + '" value="' + stopword + '" ' + attrs + '>';
return '<input class="form-control form-control-sm" id="' + elementId + '" value="' + escape(stopword) + '" ' + attrs + '>';
}

/**
Expand Down Expand Up @@ -286,6 +286,21 @@ function() {
);
}
}

const escape = (text) => {
const map = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#039;',
};

return text.replace(/[&<>"']/g, (mapped) => {
return map[mapped];
});
};

</script>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/src/phpMyFAQ/Stopwords.php
Expand Up @@ -192,7 +192,7 @@ public function getByLang($lang = null, $wordsOnly = false): array

if ($wordsOnly) {
while (($row = $this->config->getDb()->fetchObject($result)) == true) {
$stopWords[] = $row->stopword;
$stopWords[] = Strings::htmlentities($row->stopword);
}
} else {
return $this->config->getDb()->fetchAll($result);
Expand Down

0 comments on commit 7f0f921

Please sign in to comment.