From: Mark Oteiza Date: Sun, 10 Sep 2017 03:12:47 +0000 (-0400) Subject: Avoid looking at localized strings X-Git-Tag: emacs-26.0.90~209 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=e716538911227e1bedb48978b8025106abce3734;p=emacs.git Avoid looking at localized strings * 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. --- diff --git a/lisp/xdg.el b/lisp/xdg.el index 102e34cb0ce..8a475ce7d90 100644 --- a/lisp/xdg.el +++ b/lisp/xdg.el @@ -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 index 00000000000..42da83910da --- /dev/null +++ b/test/data/xdg/l10n.desktop @@ -0,0 +1,5 @@ +# localized strings +[Desktop Entry] +Comment=Cheers +Comment[en_US@piglatin]=Eerschay +Comment[sv]=Skål diff --git a/test/lisp/xdg-tests.el b/test/lisp/xdg-tests.el index 4822a05c1e4..2630e1e8248 100644 --- a/test/lisp/xdg-tests.el +++ b/test/lisp/xdg-tests.el @@ -45,7 +45,18 @@ (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 \";\"."