Merge pull request #458 from kiwix/html_decoded_suggestions

Correctly encoding/decoding HTML entities in search suggestions
This commit is contained in:
Kelson 2021-03-04 14:34:47 +01:00 committed by GitHub
commit bd781f8e8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -4,6 +4,10 @@
<script type="text/javascript" src="{{root}}/skin/jquery-ui/external/jquery/jquery.js"></script> <script type="text/javascript" src="{{root}}/skin/jquery-ui/external/jquery/jquery.js"></script>
<script type="text/javascript" src="{{root}}/skin/jquery-ui/jquery-ui.min.js"></script> <script type="text/javascript" src="{{root}}/skin/jquery-ui/jquery-ui.min.js"></script>
<script> <script>
function htmlDecode(input) {
var doc = new DOMParser().parseFromString(input, "text/html");
return doc.documentElement.textContent;
}
var jk = jQuery.noConflict(); var jk = jQuery.noConflict();
jk(function() { jk(function() {
jk( "#kiwixsearchbox" ).autocomplete({ jk( "#kiwixsearchbox" ).autocomplete({
@ -12,6 +16,13 @@
dataType: "json", dataType: "json",
cache: false, cache: false,
response: function( event, ui ) {
for(const item of ui.content) {
item.label = htmlDecode(item.label);
item.value = htmlDecode(item.value);
}
},
select: function(event, ui) { select: function(event, ui) {
jk( "#kiwixsearchbox" ).val(ui.item.value); jk( "#kiwixsearchbox" ).val(ui.item.value);
jk( "#kiwixsearchform" ).submit(); jk( "#kiwixsearchform" ).submit();

View File

@ -2,6 +2,6 @@
{{#suggestions}}{{^first}},{{/first}} {{#suggestions}}{{^first}},{{/first}}
{ {
"value" : "{{value}}", "value" : "{{value}}",
"label" : "{{& label}}" "label" : "{{label}}"
}{{/suggestions}} }{{/suggestions}}
] ]