Codificar correctamente los parámetros de búsqueda

This commit is contained in:
f 2021-09-17 15:38:56 -03:00
parent 1ff252e328
commit 4151338500

View file

@ -16,10 +16,10 @@ export default class extends Controller {
} }
connect () { connect () {
const q = window.location.search.match(/^\?q=(?<q>.*)&?/) const q = new URLSearchParams(window.location.search).get('q').trim()
if (q) { if (q) {
this.qTarget.value = decodeURI(q.groups.q) this.qTarget.value = q
this.search() this.search()
} }
} }
@ -52,8 +52,9 @@ export default class extends Controller {
const template = await request.text() const template = await request.text()
const html = await this.engine.parseAndRender(template, { q, site, results }) const html = await this.engine.parseAndRender(template, { q, site, results })
const title = `${site.i18n.search.title} - ${q}` const title = `${site.i18n.search.title} - ${q}`
const query = new URLSearchParams({ q })
window.history.pushState({ q }, title, `?q=${encodeURI(q)}`) window.history.pushState({ q }, title, `?${query.toString()}`)
document.title = title document.title = title
main.innerHTML = html main.innerHTML = html