Better directory validation; handle :UNSPECIFIC

(Olof-Joachim Frahm)
parent c561f241
......@@ -790,7 +790,7 @@ public class Pathname extends LispObject {
// :UNSPECIFIC cause the field to be treated as if it were empty. That
// is, both NIL and :UNSPECIFIC cause the component not to appear in
// the namestring." 19.2.2.2.3.1
if (directory != NIL) {
if (directory != NIL && directory != Keyword.UNSPECIFIC) {
final char separatorChar = '/';
LispObject temp = directory;
LispObject part = temp.car();
......@@ -819,9 +819,6 @@ public class Pathname extends LispObject {
sb.append("**");
} else if (part == Keyword.UP) {
sb.append("..");
} else {
error(new FileError("Unsupported directory component " + part.princToString() + ".",
this));
}
sb.append(separatorChar);
temp = temp.cdr();
......@@ -1480,6 +1477,7 @@ public class Pathname extends LispObject {
}
p.version = version;
p.validateDirectory(true);
return p;
}
......@@ -1501,6 +1499,9 @@ public class Pathname extends LispObject {
private final boolean validateDirectory(boolean signalError) {
LispObject temp = directory;
if (temp == Keyword.UNSPECIFIC) {
return true;
}
while (temp != NIL) {
LispObject first = temp.car();
temp = temp.cdr();
......@@ -1517,6 +1518,16 @@ public class Pathname extends LispObject {
}
return false;
}
} else if (first != Keyword.RELATIVE
&& first != Keyword.WILD
&& first != Keyword.UP
&& first != Keyword.BACK
&& !(first instanceof AbstractString)) {
if (signalError) {
error(new FileError("Unsupported directory component " + first.princToString() + ".",
this));
}
return false;
}
}
return true;
......
......@@ -1722,3 +1722,13 @@
(pathname-name p) (pathname-type p) (pathname-version p) (pathname-directory p)))
:wild :wild :wild (:absolute :wild))
(deftest pathname.make-pathname.3
(signals-error
(make-pathname :directory '(:absolute ("a" "b")))
'file-error)
t)
(deftest pathname.make-pathname.4
(directory-namestring (make-pathname :directory :unspecific))
"")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment