Skip to content

Commit

Permalink
[Core] Fix: URI encoding issues in core.searchform.js
Browse files Browse the repository at this point in the history
  • Loading branch information
TiSiE committed Nov 17, 2017
1 parent f64e7c9 commit 52cbfec
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
29 changes: 18 additions & 11 deletions module/Core/public/js/core.searchform.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@

} else if (tag == 'select') {
var selected = -1;
$input.find('option[selected]').each(function() {
selected = $(this).prop('index');
});
if (true === $input.data('clearOnSelect')) {
$input.html('');
} else {
$input.find('option[selected]').each(function () {
selected = $(this).prop('index');
});
}
this.selectedIndex = selected;

$input.trigger('change', {isSelect2Change: true});
Expand Down Expand Up @@ -90,11 +94,12 @@
$paginator.paginationContainer('load', baseUri + '?' + toQuery(query));
}

function toQuery(data)
function toQuery(data, encode)
{
var queryParts = [];
$.each(data, function(name, value) {
value=encodeURIComponent(value);
name=encodeURIComponent(name);
queryParts.push(name + '=' + value);
});

Expand Down Expand Up @@ -125,11 +130,11 @@
});
}

parsed[separator+encodeURIComponent(parsedName)] = value.join(separator);
parsed[separator+parsedName] = value.join(separator);
processed.push(item.name);

} else {
parsed[encodeURIComponent(item.name)] = item.value;
parsed[item.name] = item.value;
}
});

Expand All @@ -139,19 +144,21 @@

function parseQueryString(queryStr, filter, exclude)
{
queryStr = queryStr.replace(/\%26/g, '__and__');
queryStr = decodeURIComponent(queryStr);
//queryStr = queryStr.replace(/\%26/g, '__and__');
//queryStr = decodeURIComponent(queryStr);
var vars = queryStr.split('&');
var data = {};

for (i=0, c=vars.length; i<c; i++) {
vars[i] = vars[i].replace(/__and__/g, '&');
var varParts = vars[i].split('=');
if ((exclude && -1 != $.inArray(varParts[0], filter))
|| (!exclude && -1 == $.inArray(varParts[0], filter))
var name=decodeURIComponent(varParts[0]);
var value=decodeURIComponent(varParts[1]);
if ((exclude && -1 != $.inArray(name, filter))
|| (!exclude && -1 == $.inArray(name, filter))
) { continue; }

data[encodeURIComponent(varParts[0])] = encodeURIComponent(varParts[1]);
data[name] = value;
}

return data;
Expand Down
2 changes: 1 addition & 1 deletion module/Geo/public/js/geoselect.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
console.debug("initVal " + i + ": "+ initialValue[i]);
var $option = $('<option selected>Test</option>');
$option.val(initialValue[i]);
$option.text(formatSelection({id: initialValue[i], data: $.parseJSON(initialValue[i])}));
$option.text(formatSelection({id: JSON.stringify(initialValue[i]), data: initialValue[i]}));
$node.prepend($option);
}
$node.trigger('change');
Expand Down
3 changes: 2 additions & 1 deletion module/Geo/src/Geo/Form/GeoSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ public function init()
$this->setAttributes([
'data-placeholder' => /*@translate*/ 'Location',
'data-autoinit' => false,
'data-clear-on-reset' => true,
'class' => 'geoselect',
]);

}
}
}

0 comments on commit 52cbfec

Please sign in to comment.