diff options
| author | Danilo M. <danix@danix.xyz> | 2026-11-26 11:10:07 +0100 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-11-26 11:10:07 +0100 |
| commit | 3fe5cf3fcadd836b1b50efbb32f628044ad63e9f (patch) | |
| tree | 8b3e82da6b91f5c424c70810f243f88815384c99 /desktop/modules/mimeapps/test_mimeapps.js | |
| parent | 79408ae88bccf691106ce8f7c18f4be107ad3c4e (diff) | |
| download | quickshell-3fe5cf3fcadd836b1b50efbb32f628044ad63e9f.tar.gz quickshell-3fe5cf3fcadd836b1b50efbb32f628044ad63e9f.zip | |
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 <noreply@anthropic.com>
Diffstat (limited to 'desktop/modules/mimeapps/test_mimeapps.js')
| -rw-r--r-- | desktop/modules/mimeapps/test_mimeapps.js | 8 |
1 files changed, 8 insertions, 0 deletions
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 }); |
