From 3fe5cf3fcadd836b1b50efbb32f628044ad63e9f Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Thu, 26 Nov 2026 11:10:07 +0100 Subject: fix(mimeapps): duplicate keys, CRLF MimeType lines parse() lets the last duplicate key win, as GKeyFile does, but set() and remove() only touched the first, so on a file with two lines for one type an edit had no visible effect. set() now rewrites the first match and drops the later ones; remove() drops every match. A .desktop file with CRLF line endings left a \r on its MimeType= line, which scan() returned as a bogus last mime type. Each item is trimmed. Co-Authored-By: Claude Opus 5.5 --- desktop/modules/mimeapps/test_mimeapps.js | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'desktop/modules/mimeapps/test_mimeapps.js') diff --git a/desktop/modules/mimeapps/test_mimeapps.js b/desktop/modules/mimeapps/test_mimeapps.js index 469c9a4..7f629db 100644 --- a/desktop/modules/mimeapps/test_mimeapps.js +++ b/desktop/modules/mimeapps/test_mimeapps.js @@ -45,6 +45,12 @@ assert.strictEqual(M.remove(file, "text/html"), file.replace("text/html=firefox. assert.strictEqual(M.remove(file, "nope/x"), file); assert.strictEqual(M.remove("[Default Applications]\na/b=y.desktop;\n", "a/b"), "[Default Applications]\n"); +// Duplicate keys: parse takes the last; set edits the first and drops the rest; remove drops all. +const dup = "[Default Applications]\ntext/html=a.desktop;\ntext/html=b.desktop;\n"; +assert.strictEqual(M.parse(dup)["text/html"], "b.desktop"); +assert.strictEqual(M.set(dup, "text/html", "c.desktop"), "[Default Applications]\ntext/html=c.desktop;\n"); +assert.strictEqual(M.remove(dup, "text/html"), "[Default Applications]\n"); + // dirs: the user's first, trailing slashes dropped. const dirs = M.dirs("/home/you", "", "/usr/local/share/:/usr/share"); assert.deepStrictEqual(dirs, ["/home/you/.local/share/applications", "/usr/local/share/applications", "/usr/share/applications"]); @@ -56,6 +62,8 @@ const out = "/home/you/.local/share/applications/firefox.desktop:MimeType=text/h + "/usr/share/applications/kde4/okular.desktop:MimeType=application/pdf;\n"; assert.deepStrictEqual(M.scan(out, dirs), { "firefox.desktop": ["text/html"], "kde4-okular.desktop": ["application/pdf"] }); assert.deepStrictEqual(M.scan("", dirs), {}); +// A CRLF .desktop file leaves a \r on the line; it is not a mime type. +assert.deepStrictEqual(M.scan("/usr/share/applications/a.desktop:MimeType=a/b;c/d;\r\n", dirs), { "a.desktop": ["a/b", "c/d"] }); // role: the app most types point at, and how many distinct apps. assert.deepStrictEqual(M.role({ a: "x.desktop", b: "y.desktop", c: "x.desktop" }, ["a", "b", "c", "d"]), { id: "x.desktop", apps: 2 }); -- cgit v1.2.3