emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] 33/119: ews-subdirectoryp convenience function


From: Eric Schulte
Subject: [elpa] 33/119: ews-subdirectoryp convenience function
Date: Mon, 10 Mar 2014 16:57:11 +0000

eschulte pushed a commit to branch master
in repository elpa.

commit 6fc50728435c805825a22810974e9caafd247f4e
Author: Eric Schulte <address@hidden>
Date:   Sat Dec 21 06:59:11 2013 -0700

    ews-subdirectoryp convenience function
---
 emacs-web-server.el |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/emacs-web-server.el b/emacs-web-server.el
index 2d276d5..2a176fd 100644
--- a/emacs-web-server.el
+++ b/emacs-web-server.el
@@ -278,5 +278,16 @@ Optionally explicitly set MIME-TYPE, otherwise it is 
guessed by
         (insert-file-contents-literally path)
         (buffer-string)))))
 
+(defun ews-subdirectoryp (parent path)
+  "Check that PATH is a subdirectory of PARENT.
+If so return PATH, if not return nil."
+  (let* ((expanded (expand-file-name path))
+         (complete (if (string= (substring expanded -1) "/")
+                       expanded
+                     (concat expanded "/"))))
+    (and (>= (length complete) (length parent))
+         (string= parent (substring complete 0 (length parent)))
+         complete)))
+
 (provide 'emacs-web-server)
 ;;; emacs-web-server.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]