[armedbear-cvs] r13353 - in trunk/abcl: doc/design/pathnames src/org/armedbear/lisp test/lisp/abcl
mevenson at common-lisp.net
mevenson at common-lisp.net
Tue Jun 21 10:11:11 UTC 2011
Author: mevenson
Date: Tue Jun 21 03:11:10 2011
New Revision: 13353
Log:
Fix problems with whitespace in JAR-PATHNAME.
For dealing with URI Encoding (also known as [Percent Encoding]() we
implement the following rules which were implicitly.
[Percent Encoding]: http://en.wikipedia.org/wiki/Percent-encoding
1. All pathname components are represented "as is" without escaping.
2. Namestrings are suitably escaped if the Pathname is a URL-PATHNAME
or a JAR-PATHNAME.
3. Namestrings should all "round-trip":
(when (typep p 'pathname)
(equal (namestring p)
(namestring (pathname p))))
Users may use EXT:URI-ENCODE and EXT:URI-DECODE to access the escaping
rules in circumstances where they wish to manipulate PATHNAME
namestrings more directly.
All tests in JAR-PATHNAMES now pass.
Constructors for PATHNAME now produce ERROR rather than FILE-ERROR as
CLHS says "The type file-error consists of error conditions that occur
during an attempt to open or close a file, or during some low-level
transactions with a file system," which doesn't apply here.
Modified:
trunk/abcl/doc/design/pathnames/jar-pathnames.markdown
trunk/abcl/doc/design/pathnames/url-pathnames.markdown
trunk/abcl/src/org/armedbear/lisp/Load.java
trunk/abcl/src/org/armedbear/lisp/Pathname.java
trunk/abcl/test/lisp/abcl/jar-pathname.lisp
Modified: trunk/abcl/doc/design/pathnames/jar-pathnames.markdown
==============================================================================
--- trunk/abcl/doc/design/pathnames/jar-pathnames.markdown Tue Jun 21 01:30:25 2011 (r13352)
+++ trunk/abcl/doc/design/pathnames/jar-pathnames.markdown Tue Jun 21 03:11:10 2011 (r13353)
@@ -3,7 +3,7 @@
Mark Evenson
Created: 09 JAN 2010
- Modified: 26 NOV 2010
+ Modified: 21 JUN 2011
Notes towards an implementation of "jar:" references to be contained
in Common Lisp `PATHNAME`s within ABCL.
@@ -271,6 +271,14 @@
}
+URI Encoding
+------------
+
+As a subtype of URL-PATHNAMES, JAR-PATHNAMES follow all the rules for
+that type. Most notably this means that all #\Space characters should
+be encoded as '%20' when dealing with jar entries.
+
+
History
-------
Modified: trunk/abcl/doc/design/pathnames/url-pathnames.markdown
==============================================================================
--- trunk/abcl/doc/design/pathnames/url-pathnames.markdown Tue Jun 21 01:30:25 2011 (r13352)
+++ trunk/abcl/doc/design/pathnames/url-pathnames.markdown Tue Jun 21 03:11:10 2011 (r13353)
@@ -3,7 +3,7 @@
Mark Evenson
Created: 25 MAR 2010
- Modified: 26 NOV 2010
+ Modified: 21 JUN 2011
Notes towards an implementation of URL references to be contained in
Common Lisp `PATHNAME` objects within ABCL.
@@ -119,14 +119,39 @@
A URL Pathname has type URL-PATHNAME, derived from PATHNAME.
+
+URI Encoding
+------------
+
+For dealing with URI Encoding (also known as [Percent Encoding]() we
+adopt the following rules
+
+[Percent Encoding]: http://en.wikipedia.org/wiki/Percent-encoding
+
+1. All pathname components are represented "as is" without escaping.
+
+2. Namestrings are suitably escaped if the Pathname is a URL-PATHNAME
+ or a JAR-PATHNAME.
+
+3. Namestrings should all "round-trip":
+
+ (when (typep p 'pathname)
+ (equal (namestring p)
+ (namestring (pathname p))))
+
+
Status
------
This design has been implemented.
+
History
-------
26 NOV 2010 Changed implemenation to use URI encodings for the "file"
schemes including those nested with the "jar" scheme by like
aka. "jar:file:/location/of/some.jar!/".
+
+21 JUN 2011 Fixed implementation to properly handle URI encodings
+ refering nested jar archive.
Modified: trunk/abcl/src/org/armedbear/lisp/Load.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/Load.java Tue Jun 21 01:30:25 2011 (r13352)
+++ trunk/abcl/src/org/armedbear/lisp/Load.java Tue Jun 21 03:11:10 2011 (r13353)
@@ -153,12 +153,12 @@
if (Utilities.checkZipFile(truename)) {
String n = truename.getNamestring();
- n = Pathname.uriEncode(n);
+ String name = Pathname.uriEncode(truename.name.getStringValue());
if (n.startsWith("jar:")) {
- n = "jar:" + n + "!/" + truename.name.getStringValue() + "."
+ n = "jar:" + n + "!/" + name + "."
+ COMPILE_FILE_INIT_FASL_TYPE;
} else {
- n = "jar:file:" + n + "!/" + truename.name.getStringValue() + "."
+ n = "jar:file:" + n + "!/" + name + "."
+ COMPILE_FILE_INIT_FASL_TYPE;
}
mergedPathname = new Pathname(n);
Modified: trunk/abcl/src/org/armedbear/lisp/Pathname.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/Pathname.java Tue Jun 21 01:30:25 2011 (r13352)
+++ trunk/abcl/src/org/armedbear/lisp/Pathname.java Tue Jun 21 03:11:10 2011 (r13353)
@@ -280,11 +280,11 @@
url = new URL("file:" + file);
uri = url.toURI();
} catch (MalformedURLException e1) {
- error(new FileError("Failed to create URI from "
+ error(new SimpleError("Failed to create URI from "
+ "'" + file + "'"
+ ": " + e1.getMessage()));
} catch (URISyntaxException e2) {
- error(new FileError("Failed to create URI from "
+ error(new SimpleError("Failed to create URI from "
+ "'" + file + "'"
+ ": " + e2.getMessage()));
}
@@ -326,7 +326,7 @@
try {
url = new URL(jarURL);
} catch (MalformedURLException ex) {
- error(new FileError("Failed to parse URL "
+ error(new LispError("Failed to parse URL "
+ "'" + jarURL + "'"
+ ex.getMessage()));
}
@@ -339,7 +339,7 @@
device = d.device;
}
s = "/" + s.substring(separatorIndex + jarSeparator.length());
- Pathname p = new Pathname(s);
+ Pathname p = new Pathname("file:" + s); // Use URI escaping rules
directory = p.directory;
name = p.name;
type = p.type;
@@ -361,13 +361,13 @@
try {
uri = url.toURI();
} catch (URISyntaxException ex) {
- error(new FileError("Improper URI syntax for "
+ error(new SimpleError("Improper URI syntax for "
+ "'" + url.toString() + "'"
+ ": " + ex.toString()));
}
final String uriPath = uri.getPath();
if (null == uriPath) {
- error(new FileError("The URI has no path: " + uri));
+ error(new LispError("The URI has no path: " + uri));
}
final File file = new File(uriPath);
final Pathname p = new Pathname(file.getPath());
@@ -2487,9 +2487,8 @@
} catch (URISyntaxException e) {}
return null; // Error
}
-
-
- @DocString(name="uri-encode",
+
+ @DocString(name="uri-encode",
args="string => string",
doc="Encode percent escape sequences in the manner of URI encodings.")
private static final Primitive URI_ENCODE = new pf_uri_encode();
Modified: trunk/abcl/test/lisp/abcl/jar-pathname.lisp
==============================================================================
--- trunk/abcl/test/lisp/abcl/jar-pathname.lisp Tue Jun 21 01:30:25 2011 (r13352)
+++ trunk/abcl/test/lisp/abcl/jar-pathname.lisp Tue Jun 21 03:11:10 2011 (r13353)
@@ -116,9 +116,13 @@
(jar-file-init))
, at body)))
+(defun jar-pathname-escaped (jar path)
+ (pathname (format nil "jar:file:~A!/~A"
+ (ext:uri-encode (namestring jar)) path)))
+
(defmacro load-from-jar (jar path)
`(with-jar-file-init
- (load (format nil "jar:file:~A!/~A" ,jar ,path))))
+ (load (jar-pathname-escaped ,jar ,path))))
(deftest jar-pathname.load.1
(load-from-jar *tmp-jar-path* "foo")
@@ -136,7 +140,7 @@
(load-from-jar *tmp-jar-path* "eek")
t)
-(deftest jar-pathname.load.5
+çu(deftest jar-pathname.load.5
(load-from-jar *tmp-jar-path* "eek.lisp")
t)
@@ -169,15 +173,19 @@
t)
(deftest jar-pathname.load.13
- (load-from-jar *tmp-jar-path* "a/b/foo bar.abcl")
+ (signals-error
+ (load-from-jar *tmp-jar-path* "a/b/foo bar.abcl")
+ 'error)
t)
(deftest jar-pathname.load.14
- (load-from-jar *tmp-jar-path-whitespace* "a/b/foo.abcl")
+ (load-from-jar *tmp-jar-path-whitespace* "a/b/bar.abcl")
t)
(deftest jar-pathname.load.15
- (load-from-jar *tmp-jar-path-whitespace* "a/b/foo bar.abcl")
+ (signals-error
+ (load-from-jar *tmp-jar-path-whitespace* "a/b/foo bar.abcl")
+ 'error)
t)
(deftest jar-pathname.load.16
@@ -279,7 +287,7 @@
(deftest jar-pathname.merge-pathnames.2
(merge-pathnames
- "bar.abcl" #p"jar:file:baz.jar!/foo/")
+ "bar.abcl" #p"jar:file:baz.jar!/foo/baz")
#p"jar:file:baz.jar!/foo/bar.abcl")
(deftest jar-pathname.merge-pathnames.3
@@ -404,7 +412,7 @@
(let ((s "jar:file:/foo/bar/a space/that!/this"))
(equal s
(namestring (pathname s))))
- 'file-error)
+ 'error)
t)
(deftest jar-pathname.11
More information about the armedbear-cvs
mailing list