Skip to content

Commit

Permalink
🐛 fix for #70 (sanitize FlexSearch input) (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
colinwilson authored Sep 16, 2023
2 parents b7ebc7b + 2082804 commit e4dbd49
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion assets/docs/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,11 @@ if (document.getElementById("relativetime")) {

// Initialize Bootstrap Tooltips
const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]')
const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new Tooltip(tooltipTriggerEl))
const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new Tooltip(tooltipTriggerEl))

// Sanitize HTML function
const sanitizeHTML = function (string) {
const temp = document.createElement('div');
temp.textContent = string;
return temp.innerHTML;
};
2 changes: 1 addition & 1 deletion layouts/partials/docs/footer/flexsearch.html
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
function show_results(){
const maxResult = {{ .Site.Params.flexsearch.maxResult | default 5}};
const minlength = {{ .Site.Params.flexsearch.minQueryChar | default 0}};
var searchQuery = this.value;
var searchQuery = sanitizeHTML(this.value);
var results = index.search(searchQuery, {limit: maxResult, enrich: true});

// flatten results since index.search() returns results for each indexed field
Expand Down

0 comments on commit e4dbd49

Please sign in to comment.