fix(admin): keep the filter query intact in console pager and export links #49
Reference in New Issue
Block a user
Delete Branch "feature/admin-pager-filter-encoding"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Симптом
В админ-консоли пагинация и экспорт теряли активный фильтр. Пример: на
/_gm/users?kind=robotsссылка «next» вела на/_gm/users?kind%3drobots&page=2вместо…?kind=robots&page=2.Корень
FilterQuery— это уже закодированная строка запроса (url.Values.Encode), но подставлялась после?вhref. Тамhtml/templateсчитает её одним значением query-параметра и повторно процентно-кодирует структурные=/&:kind=robots→kind%3drobots. Наmessagesхуже — мультифильтр (game=…&user=…) схлопывался в один мусорный параметр; ломалась и ссылка экспорта CSV.Фикс
FilterQueryтипизирован какtemplate.URL— уже экранированный фрагмент отдаётся как есть (атрибутный&→&корректен, браузер декодирует обратно). Безопасно: выводurl.Values.Encodeстрого процентно-кодирован.games/complaintsиспользуютstatus={{.Status}}— одиночное значение в правильном контексте — и не затронуты.Тесты
Новый
TestPagerLinksPreserveFilterQuery(users + messages, включая CSV-ссылку).gofmt -l/go build/go vetчисто; пакетыadminconsoleиserverзелёные.The paginated users and messages lists interpolate the pre-encoded filter query (url.Values.Encode) after the "?" in their pager and CSV-export links. There html/template treats it as a single query value and percent-encodes the structural "=" and "&" again, so "kind=robots" rendered as "kind%3drobots" and the multi-pair message filter collapsed -- every page step dropped the active filter. Type FilterQuery as template.URL so the already-escaped fragment is emitted verbatim (the attribute-level "&" -> "&" stays correct, the browser decodes it back). It is safe because url.Values.Encode output is strictly percent-encoded. games/complaints use status={{.Status}} -- a single value in proper query-value context -- and were never affected.