]> git.eshelyaron.com Git - emacs.git/commitdiff
Avoid looking at localized strings
authorMark Oteiza <mvoteiza@udel.edu>
Sun, 10 Sep 2017 03:12:47 +0000 (23:12 -0400)
committerMark Oteiza <mvoteiza@udel.edu>
Sun, 10 Sep 2017 03:14:07 +0000 (23:14 -0400)
* lisp/xdg.el (xdg-desktop-read-group): Add condition to catch
localized strings.
* test/lisp/xdg-tests.el (xdg-desktop-parsing): Add test to ensure
parsing l10n strings doesn't error but is essentially a no-op.

lisp/xdg.el
test/data/xdg/l10n.desktop [new file with mode: 0644]
test/lisp/xdg-tests.el

index 102e34cb0ce381aea6d46cd1dcce7cfee40a2740..8a475ce7d90fe5fbfc9051e642fe829893a34a2f 100644 (file)
@@ -177,6 +177,8 @@ This should be called at the beginning of a line."
        ((= (following-char) ?#))
        ((looking-at xdg-desktop-entry-regexp)
         (puthash (match-string 1) (match-string 2) res))
+       ;; Filter localized strings
+       ((looking-at (rx (group-n 1 (+ (in alnum "-"))) (* blank) "[")))
        (t (error "Malformed line: %s"
                  (buffer-substring (point) (point-at-eol)))))
       (forward-line))
diff --git a/test/data/xdg/l10n.desktop b/test/data/xdg/l10n.desktop
new file mode 100644 (file)
index 0000000..42da839
--- /dev/null
@@ -0,0 +1,5 @@
+# localized strings
+[Desktop Entry]
+Comment=Cheers
+Comment[en_US@piglatin]=Eerschay
+Comment[sv]=Skål
index 4822a05c1e4ad68787c64c42bc99a46de89d2b2a..2630e1e8248169dd3d114dfebf534ff10002cdac 100644 (file)
     (expand-file-name "wrong.desktop" xdg-tests-data-dir)))
   (should-error
    (xdg-desktop-read-file
-    (expand-file-name "malformed.desktop" xdg-tests-data-dir))))
+    (expand-file-name "malformed.desktop" xdg-tests-data-dir)))
+  (let ((tab (xdg-desktop-read-file
+              (expand-file-name "l10n.desktop" xdg-tests-data-dir)))
+        (env (getenv "LC_MESSAGES")))
+    (unwind-protect
+        (progn
+          (setenv "LC_MESSAGES" nil)
+          (should (equal (gethash "Comment" tab) "Cheers"))
+          ;; l10n omitted
+          (setenv "LC_MESSAGES" "sv_SE.UTF-8")
+          (should-not (equal (gethash "Comment" tab) "Skål")))
+      (setenv "LC_MESSAGES" env))))
 
 (ert-deftest xdg-desktop-strings-type ()
   "Test desktop \"string(s)\" type: strings delimited by \";\"."