A platform for community discussion. Free, open, simple.
FIX: 404 when switching categories with the "No tags" filter active (#39894)
Régis Hanol3941bc54df47
diff --git a/frontend/discourse/app/lib/url.js b/frontend/discourse/app/lib/url.jsindex 2bb2487c7a4..dce14d372c9 100644--- a/frontend/discourse/app/lib/url.js+++ b/frontend/discourse/app/lib/url.js@@ -572,29 +572,23 @@ export function getCategoryAndTagUrl(category, subcategories, tag) {if (category) {url = category.path;- if (category.default_list_filter === "none" && subcategories) {- if (subcategories) {- url += "/all";- } else {- url += "/none";- }- } else if (!subcategories) {+ if (!subcategories) {url += "/none";+ } else if (category.default_list_filter === "none") {+ url += "/all";}}if (tag) {- // tag can be string "none" (special filter) or object with {id, name, slug}- if (typeof tag === "string") {- // special case: "none" filter- url = url ? "/tags" + url + "/" + tag : "/tag/" + tag;- } else {- if (url) {- url = "/tags" + url + "/" + tag.slug + "/" + tag.id;- } else {- url = "/tag/" + tag.slug + "/" + tag.id;- }- }+ // tag can be string "none" (special filter) or object with {id, name, slug}.+ // A Tag model with a null id also represents the "no tags" filter — handle+ // it the same as the string form so we don't produce ".../none/null" URLs.+ const isString = typeof tag === "string";+ const slug = isString ? tag : tag.slug;+ const id = isString ? null : tag.id;++ const prefix = url ? `/tags${url}` : "/tag";+ url = id ? `${prefix}/${slug}/${id}` : `${prefix}/${slug}`;}return getURL(url || "/");diff --git a/frontend/discourse/tests/unit/lib/url-test.js b/frontend/discourse/tests/unit/lib/url-test.jsindex dc3ac128130..cb740db2230 100644--- a/frontend/discourse/tests/unit/lib/url-test.js+++ b/frontend/discourse/tests/unit/lib/url-test.js@@ -226,37 +226,34 @@ module("Unit | Utility | url", function (hooks) {});test("getCategoryAndTagUrl", function (assert) {+ const cat = { path: "/c/foo/1", default_list_filter: "all" };+ const noneCat = { path: "/c/foo/1", default_list_filter: "none" };+ const noneTag = { slug: "none", id: null };+ const bugTag = { slug: "bug", id: 7 };++ // category only+ assert.strictEqual(getCategoryAndTagUrl(cat, true), "/c/foo/1");+ assert.strictEqual(getCategoryAndTagUrl(cat, false), "/c/foo/1/none");+ assert.strictEqual(getCategoryAndTagUrl(noneCat, true), "/c/foo/1/all");+ assert.strictEqual(getCategoryAndTagUrl(noneCat, false), "/c/foo/1/none");++ // category + tagassert.strictEqual(- getCategoryAndTagUrl(- { path: "/c/foo/1", default_list_filter: "all" },- true- ),- "/c/foo/1"+ getCategoryAndTagUrl(cat, true, "none"),+ "/tags/c/foo/1/none");-assert.strictEqual(- getCategoryAndTagUrl(- { path: "/c/foo/1", default_list_filter: "all" },- false- ),- "/c/foo/1/none"+ getCategoryAndTagUrl(cat, true, noneTag),+ "/tags/c/foo/1/none");-assert.strictEqual(- getCategoryAndTagUrl(- { path: "/c/foo/1", default_list_filter: "none" },- true- ),- "/c/foo/1/all"+ getCategoryAndTagUrl(cat, true, bugTag),+ "/tags/c/foo/1/bug/7");- assert.strictEqual(- getCategoryAndTagUrl(- { path: "/c/foo/1", default_list_filter: "none" },- false- ),- "/c/foo/1/none"- );+ // tag only+ assert.strictEqual(getCategoryAndTagUrl(null, true, "none"), "/tag/none");+ assert.strictEqual(getCategoryAndTagUrl(null, true, bugTag), "/tag/bug/7");});test("routeTo redirects secure uploads URLS because they are server side only", async function (assert) {