Changeset 13353


Ignore:
Timestamp:
06/21/11 10:11:10 (10 years ago)
Author:
Mark Evenson
Message:

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.
  1. Namestrings are suitably escaped if the Pathname is a URL-PATHNAME

or a JAR-PATHNAME.

  1. 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.

Location:
trunk/abcl
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/doc/design/pathnames/jar-pathnames.markdown

    r13058 r13353  
    44    Mark Evenson
    55    Created:  09 JAN 2010
    6     Modified: 26 NOV 2010
     6    Modified: 21 JUN 2011
    77
    88Notes towards an implementation of "jar:" references to be contained
     
    270270       type: "lisp
    271271    }
     272
     273
     274URI Encoding
     275------------
     276
     277As a subtype of URL-PATHNAMES, JAR-PATHNAMES follow all the rules for
     278that type.  Most notably this means that all #\Space characters should
     279be encoded as '%20' when dealing with jar entries.
    272280
    273281
  • trunk/abcl/doc/design/pathnames/url-pathnames.markdown

    r13058 r13353  
    44    Mark Evenson
    55    Created:  25 MAR 2010
    6     Modified: 26 NOV 2010
     6    Modified: 21 JUN 2011
    77
    88Notes towards an implementation of URL references to be contained in
     
    120120A URL Pathname has type URL-PATHNAME, derived from PATHNAME.
    121121
     122
     123URI Encoding
     124------------
     125
     126For dealing with URI Encoding (also known as [Percent Encoding]() we
     127adopt the following rules
     128
     129[Percent Encoding]: http://en.wikipedia.org/wiki/Percent-encoding
     130
     1311.  All pathname components are represented "as is" without escaping.
     132
     1332.  Namestrings are suitably escaped if the Pathname is a URL-PATHNAME
     134    or a JAR-PATHNAME.
     135
     1363.  Namestrings should all "round-trip":
     137
     138    (when (typep p 'pathname)
     139       (equal (namestring p)
     140              (namestring (pathname p))))
     141
     142
    122143Status
    123144------
    124145
    125146This design has been implemented.
     147
    126148
    127149History
     
    131153  schemes including those nested with the "jar" scheme by like
    132154  aka. "jar:file:/location/of/some.jar!/".
     155
     15621 JUN 2011 Fixed implementation to properly handle URI encodings
     157  refering nested jar archive.
  • trunk/abcl/src/org/armedbear/lisp/Load.java

    r13274 r13353  
    154154        if (Utilities.checkZipFile(truename)) {
    155155            String n = truename.getNamestring();
    156             n = Pathname.uriEncode(n);
     156            String name = Pathname.uriEncode(truename.name.getStringValue());
    157157            if (n.startsWith("jar:")) {
    158                 n = "jar:" + n + "!/" + truename.name.getStringValue() + "."
     158                n = "jar:" + n + "!/" + name + "."
    159159                    + COMPILE_FILE_INIT_FASL_TYPE;
    160160            } else {
    161                 n = "jar:file:" + n + "!/" + truename.name.getStringValue() + "."
     161                n = "jar:file:" + n + "!/" + name + "."
    162162                    + COMPILE_FILE_INIT_FASL_TYPE;
    163163            }
  • trunk/abcl/src/org/armedbear/lisp/Pathname.java

    r13349 r13353  
    281281                        uri = url.toURI();
    282282                    } catch (MalformedURLException e1) {
    283                         error(new FileError("Failed to create URI from "
     283                        error(new SimpleError("Failed to create URI from "
    284284                                            + "'" + file + "'"
    285285                                            + ": " + e1.getMessage()));
    286286                    } catch (URISyntaxException e2) {
    287                         error(new FileError("Failed to create URI from "
     287                        error(new SimpleError("Failed to create URI from "
    288288                                            + "'" + file + "'"
    289289                                            + ": " + e2.getMessage()));
     
    327327                url = new URL(jarURL);
    328328            } catch (MalformedURLException ex) {
    329                 error(new FileError("Failed to parse URL "
     329                error(new LispError("Failed to parse URL "
    330330                                    + "'" + jarURL + "'"
    331331                                    + ex.getMessage()));
     
    340340            }
    341341            s = "/" + s.substring(separatorIndex + jarSeparator.length());
    342             Pathname p = new Pathname(s);
     342            Pathname p = new Pathname("file:" + s); // Use URI escaping rules
    343343            directory = p.directory;
    344344            name = p.name;
     
    362362                    uri = url.toURI();
    363363                } catch (URISyntaxException ex) {
    364                     error(new FileError("Improper URI syntax for "
     364                    error(new SimpleError("Improper URI syntax for "
    365365                                    + "'" + url.toString() + "'"
    366366                                    + ": " + ex.toString()));
     
    368368                final String uriPath = uri.getPath();
    369369                if (null == uriPath) {
    370                     error(new FileError("The URI has no path: " + uri));
     370                    error(new LispError("The URI has no path: " + uri));
    371371                }
    372372                final File file = new File(uriPath);
     
    24882488        return null;  // Error
    24892489    }
    2490 
    2491 
    2492     @DocString(name="uri-encode",
     2490   
     2491        @DocString(name="uri-encode",
    24932492               args="string => string",
    24942493               doc="Encode percent escape sequences in the manner of URI encodings.")
  • trunk/abcl/test/lisp/abcl/jar-pathname.lisp

    r13326 r13353  
    117117       ,@body)))
    118118
     119(defun jar-pathname-escaped (jar path)
     120  (pathname (format nil "jar:file:~A!/~A"
     121                    (ext:uri-encode (namestring jar)) path)))
     122
    119123(defmacro load-from-jar (jar path)
    120124  `(with-jar-file-init
    121        (load (format nil "jar:file:~A!/~A" ,jar ,path))))
     125       (load (jar-pathname-escaped ,jar ,path))))
    122126
    123127(deftest jar-pathname.load.1
     
    137141  t)
    138142
    139 (deftest jar-pathname.load.5
     143çu(deftest jar-pathname.load.5
    140144    (load-from-jar *tmp-jar-path* "eek.lisp")
    141145  t)
     
    170174
    171175(deftest jar-pathname.load.13
    172     (load-from-jar *tmp-jar-path* "a/b/foo bar.abcl")
     176    (signals-error
     177     (load-from-jar *tmp-jar-path* "a/b/foo bar.abcl")
     178     'error)
    173179  t)
    174180
    175181(deftest jar-pathname.load.14
    176     (load-from-jar *tmp-jar-path-whitespace* "a/b/foo.abcl")
     182    (load-from-jar *tmp-jar-path-whitespace* "a/b/bar.abcl")
    177183  t)
    178184
    179185(deftest jar-pathname.load.15
    180     (load-from-jar *tmp-jar-path-whitespace* "a/b/foo bar.abcl")
     186    (signals-error
     187     (load-from-jar *tmp-jar-path-whitespace* "a/b/foo bar.abcl")
     188     'error)
    181189  t)
    182190
     
    280288(deftest jar-pathname.merge-pathnames.2
    281289    (merge-pathnames
    282      "bar.abcl" #p"jar:file:baz.jar!/foo/")
     290     "bar.abcl" #p"jar:file:baz.jar!/foo/baz")
    283291  #p"jar:file:baz.jar!/foo/bar.abcl")
    284292
     
    405413       (equal s
    406414              (namestring (pathname s))))
    407      'file-error)
     415     'error)
    408416  t)
    409417
Note: See TracChangeset for help on using the changeset viewer.