summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2019-03-10 15:11:58 +0100
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2019-03-10 18:00:36 +0100
commitc04372dbfedff361346e1b29d59b3d0688ba9b4c (patch)
tree2e4c4de7d1f1e43de485f70e0c63f45cf6d86ecc
parentc3d75b4aa26621e9ff02bc55d8542e1d249af9c9 (diff)
downloadorg-mode-c04372dbfedff361346e1b29d59b3d0688ba9b4c.tar.gz
org-lint: Add checker for obsolete link escape syntax
* lisp/org-lint.el (org-lint--checkers): Add new linter. (org-lint-percent-encoding-link-escape): New function. * testing/lisp/test-org-lint.el (test-org-lint/percenc-encoding-link-escape): New test.
-rw-r--r--lisp/org-lint.el25
-rw-r--r--testing/lisp/test-org-lint.el27
2 files changed, 51 insertions, 1 deletions
diff --git a/lisp/org-lint.el b/lisp/org-lint.el
index 19f2b0f..1131ea5 100644
--- a/lisp/org-lint.el
+++ b/lisp/org-lint.el
@@ -289,8 +289,14 @@
:description "Report obsolete \"file+application\" link"
:categories '(link obsolete))
(make-org-lint-checker
+ :name 'percent-encoding-link-escape
+ :description "Report obsolete escape syntax in links"
+ :categories '(link obsolete)
+ :trust 'low)
+ (make-org-lint-checker
:name 'spurious-colons
- :description "Report spurious colons in tags"))
+ :description "Report spurious colons in tags"
+ :categories '(tags)))
"List of all available checkers.")
(defun org-lint--collect-duplicates
@@ -884,6 +890,23 @@ Use \"export %s\" instead"
(list (org-element-property :begin l)
(format "Deprecated \"file+%s\" link type" app)))))))
+(defun org-lint-percent-encoding-link-escape (ast)
+ (org-element-map ast 'link
+ (lambda (l)
+ (when (eq 'bracket (org-element-property :format l))
+ (let* ((uri (org-element-property :path l))
+ (start 0)
+ (obsolete-flag
+ (catch :obsolete
+ (while (string-match "%\\(..\\)?" uri start)
+ (setq start (match-end 0))
+ (unless (member (match-string 1 uri) '("25" "5B" "5D" "20"))
+ (throw :obsolete nil)))
+ (string-match-p "%" uri))))
+ (when obsolete-flag
+ (list (org-element-property :begin l)
+ "Link escaped with obsolete percent-encoding syntax")))))))
+
(defun org-lint-wrong-header-argument (ast)
(let* ((reports)
(verify
diff --git a/testing/lisp/test-org-lint.el b/testing/lisp/test-org-lint.el
index b3ebe8c..587bc0b 100644
--- a/testing/lisp/test-org-lint.el
+++ b/testing/lisp/test-org-lint.el
@@ -415,6 +415,33 @@ SCHEDULED: <2012-03-29 thu.>"
(org-test-with-temp-text "[[file+emacs:foo.org]]"
(org-lint '(file-application)))))
+(ert-deftest test-org-lint/percenc-encoding-link-escape ()
+ "Test `org-lint-percent-encoding-link-escape' checker."
+ (should
+ (org-test-with-temp-text "[[A%20B]]"
+ (org-lint '(percent-encoding-link-escape))))
+ (should
+ (org-test-with-temp-text "[[%5Bfoo%5D]]"
+ (org-lint '(percent-encoding-link-escape))))
+ (should
+ (org-test-with-temp-text "[[A%2520B]]"
+ (org-lint '(percent-encoding-link-escape))))
+ (should-not
+ (org-test-with-temp-text "[[A B]]"
+ (org-lint '(percent-encoding-link-escape))))
+ (should-not
+ (org-test-with-temp-text "[[A%30B]]"
+ (org-lint '(percent-encoding-link-escape))))
+ (should-not
+ (org-test-with-temp-text "[[A%20%30B]]"
+ (org-lint '(percent-encoding-link-escape))))
+ (should-not
+ (org-test-with-temp-text "<file:A%20B>"
+ (org-lint '(percent-encoding-link-escape))))
+ (should-not
+ (org-test-with-temp-text "[[A B%]]"
+ (org-lint '(percent-encoding-link-escape)))))
+
(ert-deftest test-org-lint/wrong-header-argument ()
"Test `org-lint-wrong-header-argument' checker."
(should