diff --git a/src/filesystem-utils.lisp b/src/filesystem-utils.lisp index 96bfa10..b1805d1 100644 --- a/src/filesystem-utils.lisp +++ b/src/filesystem-utils.lisp @@ -166,8 +166,9 @@ (nix:s-isreg (nix:stat-mode (nix:stat path)))) (defun dirp (path) - (and (nix:stat path) - (nix:s-isdir (nix:stat-mode (nix:stat path))))) + (ignore-errors + (and (nix:stat path) + (nix:s-isdir (nix:stat-mode (nix:stat path)))))) (defun split-path-elements (path) (cl-ppcre:split *directory-sep-regexp* path)) diff --git a/src/iri-parser.lisp b/src/iri-parser.lisp index 071e15f..da36ddb 100644 --- a/src/iri-parser.lisp +++ b/src/iri-parser.lisp @@ -83,8 +83,10 @@ (defrule scheme (and alpha (* (or alpha digit "+" "-" "." ))) (:text t)) -(defrule ihier-part (and iauthority-start iauthority) - (:function second)) +(defrule ihier-part (or (and iauthority-start iauthority ipath-abempty) + ipath-absolute ; text + ipath-rootless ;text + ipath-empty)) ;text (defrule user-credentials (and iuserinfo credential-delim) (:function first)) @@ -169,21 +171,28 @@ (:text t)) (defun extract-fields-from-absolute-iri (parsed) - (let ((authority (third parsed))) - (list (first parsed) ; scheme - (first authority) ; user-credentials - (second authority) ; host - (third authority) ; port - (fourth parsed) ; path - (fifth parsed) ; iquery - (sixth parsed)))) ; ifragment + (let* ((scheme (first parsed)) + (ihier-part (third parsed)) + (authority (when (consp ihier-part) + (second ihier-part))) + (user-credentials (first authority)) + (host (second authority)) + (port (third authority)) + (ipath (if (consp ihier-part) + (third ihier-part) + ihier-part)) + (iquery (fourth parsed)) + (ifragment (fifth parsed))) + (list scheme + user-credentials + host + port + ipath + iquery + ifragment))) (defrule iri (and scheme ":" ihier-part - (or ipath-abempty - ipath-absolute - ipath-noscheme - ipath-empty) (? iquery) (? ifragment)) (:function extract-fields-from-absolute-iri)) diff --git a/src/tests/iri-tests.lisp b/src/tests/iri-tests.lisp index 117c29d..8f89162 100644 --- a/src/tests/iri-tests.lisp +++ b/src/tests/iri-tests.lisp @@ -61,7 +61,11 @@ ("http://" . ("http" nil nil nil nil nil nil)) ("http" . - (nil nil nil nil "http" nil nil)))) + (nil nil nil nil "http" nil nil)) + ("tel:+31-thisiisnotanumber" . + ("tel" nil nil nil "+31-thisiisnotanumber" nil nil)) + ("mailto:name@localhost.localdomain" . + ("mailto" nil nil nil "name@localhost.localdomain" nil nil)))) (deftest test-parsing (iri-suite) (loop for (a . b) in *test-cases* do diff --git a/src/tests/uri-tests.lisp b/src/tests/uri-tests.lisp index 58e927d..b75a5b5 100644 --- a/src/tests/uri-tests.lisp +++ b/src/tests/uri-tests.lisp @@ -52,9 +52,6 @@ (nil nil nil nil "http" nil nil)) ("http://" . ("http" nil nil nil nil nil nil)) - ;; are these valid URI? - ;; ("tel:+31-641044153" . - ;; ("tel" nil nil "+31-641044153" nil nil)) ;; ("http:" . ;; ("http" nil nil nil nil nil)) ("ldap://[2001:db8::7]/c=GB?objectClass?one" . diff --git a/src/uri-parser.lisp b/src/uri-parser.lisp index 086604b..320bd5d 100644 --- a/src/uri-parser.lisp +++ b/src/uri-parser.lisp @@ -17,6 +17,8 @@ (in-package :uri-parser) +;; NOTE: the parser is broken, use :iri-parser, instead + (define-constant +segment-separator+ "/" :test #'string=) (defrule alpha (character-ranges (#\a #\z) (#\A #\Z))