ob-tangle: Check that integer file modes are valid

* lisp/ob-tangle.el (org-babel-interpret-file-mode): Check that the
integer as an octal represents a valid file mode, and complain
otherwise.
This commit is contained in:
TEC 2021-11-20 22:43:44 +08:00
parent 3a6686010e
commit ff6fd93876
Signed by: tec
GPG Key ID: 779591AFDB81F06C
1 changed files with 5 additions and 1 deletions

View File

@ -317,7 +317,11 @@ The following forms are currently recognised:
* The interpretation of these forms relies on `file-modes-symbolic-to-number',
and uses `org-babel-tangle-default-mode' as the base mode."
(cond
((integerp mode) mode)
((integerp mode)
(if (string-match-p "^[0-7][0-7][0-7]$" (format "%o" mode))
mode
(user-error "%1$o is not a valid file mode octal. \
Did you give the decimal value %1$d by mistake?" mode)))
((not (stringp mode))
(error "File mode %S not recognised as a valid format." mode))
((string-match-p "^o0?[0-7][0-7][0-7]$" mode)