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

Avoid from Html injection #372

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ var EasyAutocomplete = (function(scope) {
.mouseout(function() {
config.get("list").onMouseOutEvent();
})
.html(template.build(highlight(elementsValue, phrase), listData[j]));
.html(template.build(highlight(htmlEntities(elementsValue), phrase), listData[j]));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to add a config flag for this HTML injection feature, so a user can decide whether they want to use it or not. It can be enabled by default.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah you are right. I forget the flags. I will check it tonight.

})();

$listContainer.append($item);
Expand All @@ -316,6 +316,10 @@ var EasyAutocomplete = (function(scope) {

$field.after($elements_container);
}

function htmlEntities(str) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you rename this method to striHTMLTags?

return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}

function removeContainer() {
$field.next("." + consts.getValue("CONTAINER_CLASS")).remove();
Expand Down