handler(oldFilters, newFilters) {
if (this.filterQuerystring !== '') {
- history.replaceState(newFilters, '', '?' + this.filterQuerystring);
+
+ // Using square brackets in the URL can cause problems due to URL encoding and decoding
+ // so it's better to remove them while also shortening the URL to simply use Fx=...
+ const safeQuerystring = this.filterQuerystring.replace(/filter\[(\d+)]/g, 'F$1');
+
+ history.replaceState(newFilters, '', '?' + safeQuerystring);
}
}
}
// Values may be a number or a string ('-') so don't try to convert them to integers
value = value.split(';');
- // Update the actual filter data
- $this.filters[key] = value;
+ // Update the actual filter data if the key exists
+ if ($this.filters.hasOwnProperty(key)) {
+ $this.filters[key] = value;
+ }
});
$this.updateFilters();