[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/denote 779fe017dc 3/6: Validate the presence of at leas
From: |
ELPA Syncer |
Subject: |
[elpa] externals/denote 779fe017dc 3/6: Validate the presence of at least one file name component |
Date: |
Sat, 14 Dec 2024 03:57:58 -0500 (EST) |
branch: externals/denote
commit 779fe017dcc977ff168f26575ff108e7785f02df
Author: Jean-Philippe Gagné Guay <jeanphilippe150@gmail.com>
Commit: Jean-Philippe Gagné Guay <jeanphilippe150@gmail.com>
Validate the presence of at least one file name component
---
denote.el | 18 +++++++++++-------
tests/denote-test.el | 8 ++++++++
2 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/denote.el b/denote.el
index 40f776405f..296e02de78 100644
--- a/denote.el
+++ b/denote.el
@@ -1196,11 +1196,12 @@ For our purposes, a note must satisfy `file-regular-p'
and
This tests the rules of Denote's file-naming scheme. Sluggification is
ignored. It is done by removing all file name components and validating
what remains."
- (let ((filename (file-name-nondirectory file))
- (title (denote-retrieve-filename-title file))
- (keywords-string (denote-retrieve-filename-keywords file))
- (signature (denote-retrieve-filename-signature file))
- (identifier (denote-retrieve-filename-identifier file)))
+ (let* ((initial-filename (file-name-nondirectory file))
+ (filename initial-filename)
+ (title (denote-retrieve-filename-title file))
+ (keywords-string (denote-retrieve-filename-keywords file))
+ (signature (denote-retrieve-filename-signature file))
+ (identifier (denote-retrieve-filename-identifier file)))
(when title
(setq filename (replace-regexp-in-string (concat "\\(--" (regexp-quote
title) "\\).*\\'") "" filename nil nil 1)))
(when keywords-string
@@ -1212,8 +1213,9 @@ what remains."
(setq filename (replace-regexp-in-string (concat "\\(@@"
(regexp-quote identifier) "\\).*\\'") "" filename nil nil 1))
(setq filename (replace-regexp-in-string (concat "\\(" (regexp-quote
identifier) "\\).*\\'") "" filename nil nil 1))))
;; What remains should be the empty string or the file extension.
- (or (string-empty-p filename)
- (string-prefix-p "." filename))))
+ (and (not (string-prefix-p "." initial-filename))
+ (or (string-empty-p filename)
+ (string-prefix-p "." filename)))))
(defun denote-file-has-signature-p (file)
"Return non-nil if FILE has a Denote identifier."
@@ -2227,6 +2229,8 @@ which case it is not added to the base file name."
(setq file-name (concat file-name "__" (denote-keywords-combine
(denote-sluggify-keywords keywords)))))
((and (eq component 'signature) signature (not (string-empty-p
signature)))
(setq file-name (concat file-name "==" (denote-sluggify
'signature signature))))))
+ (when (string-empty-p file-name)
+ (error "There should be at least one file name component"))
(setq file-name (concat file-name extension))
;; Do not prepend identifier with @@ if it is the first component and has
the format 00000000T000000.
(when (and (string-prefix-p "@@" file-name)
diff --git a/tests/denote-test.el b/tests/denote-test.el
index c00e80334b..3a083abfe5 100644
--- a/tests/denote-test.el
+++ b/tests/denote-test.el
@@ -311,6 +311,14 @@ does not involve the time zone."
(denote--file-extension 'org)
""))
+ (should-error (denote-format-file-name
+ (denote-directory)
+ ""
+ nil
+ ""
+ (denote--file-extension 'org)
+ ""))
+
(should (equal (denote-format-file-name
(denote-directory)
nil
- [elpa] externals/denote updated (6613d3903d -> 2ab74c1d47), ELPA Syncer, 2024/12/14
- [elpa] externals/denote 0a5c142287 1/6: Refactor denote--date-convert, ELPA Syncer, 2024/12/14
- [elpa] externals/denote 779fe017dc 3/6: Validate the presence of at least one file name component,
ELPA Syncer <=
- [elpa] externals/denote 5d4b9f9089 5/6: Merge pull request #496 from jeanphilippegg/fix-tests, ELPA Syncer, 2024/12/14
- [elpa] externals/denote 8f3e5dd407 2/6: Fix tests, ELPA Syncer, 2024/12/14
- [elpa] externals/denote 2ab74c1d47 6/6: Merge pull request #495 from jeanphilippegg/denote--date-convert, ELPA Syncer, 2024/12/14
- [elpa] externals/denote 165ef38a9b 4/6: Add denote--generate-date-for-rename, ELPA Syncer, 2024/12/14