Changeset 13026


Ignore:
Timestamp:
11/17/10 15:55:47 (13 years ago)
Author:
Mark Evenson
Message:

Further fix for #110 eliminating the use of the URLDecoder.decode().

Upon further review, the attempt to decode a URL path via the URL
unescaping functions intended for escaping HTML Forms submission is
just wrong, originating as far as I can tell in my initial Pathname
commit. There may be issues where we should treat strings of the form
'file:URI' with real URI escaping rules to remove %bb byte-encoding,
but these rules might well confuse those attempting to include '%' in
files, so we leave that to more formal specification.

Untabify Pathname.java.

Tests for correct parsing of device under Windows.

Location:
trunk/abcl
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/Pathname.java

    r13024 r13026  
    197197    public Pathname(URL url) {
    198198        if ("file".equals(url.getProtocol())) {
    199             String s;
    200             try {
    201                 s = URLDecoder.decode(url.getPath(), "UTF-8");
    202                 // But rencode \SPACE as '+'
    203                 s = s.replace(' ', '+');
    204             } catch (java.io.UnsupportedEncodingException uee) {
    205                 // Can't happen: every Java is supposed to support
    206                 // at least UTF-8 encoding
    207                 Debug.assertTrue(false);
    208                 s = null;
    209             }
     199            String s = url.getPath();
    210200            if (s != null) {
    211     if (Utilities.isPlatformWindows) {
    212         //  Workaround for Java's idea of URLs
    213         //  new (URL"file:///c:/a/b").getPath() --> "/c:/a/b"
     201                if (Utilities.isPlatformWindows) {
     202                    //  Workaround for Java's idea of URLs
     203                    //  new (URL"file:///c:/a/b").getPath() --> "/c:/a/b"
    214204                    //  whereas we need "c" to be the DEVICE.
    215         if (s.length() > 2
    216       && s.charAt(0) == '/'
    217       && s.charAt(2) == ':') {
    218       s = s.substring(1);
    219         }
    220     }
     205                    if (s.length() > 2
     206                        && s.charAt(0) == '/'
     207                        && s.charAt(2) == ':') {
     208                        s = s.substring(1);
     209                    }
     210                }
    221211                init(s);
    222212                return;
     
    654644            if (type instanceof AbstractString) {
    655645                String t = type.getStringValue();
    656     // Allow Windows shortcuts to include TYPE
    657     if (!(t.endsWith(".lnk") && Utilities.isPlatformWindows)) {
    658         if (t.indexOf('.') >= 0) {
    659       Debug.assertTrue(namestring == null);
    660       return null;
    661         }
    662     }
     646                // Allow Windows shortcuts to include TYPE
     647                if (!(t.endsWith(".lnk") && Utilities.isPlatformWindows)) {
     648                    if (t.indexOf('.') >= 0) {
     649                        Debug.assertTrue(namestring == null);
     650                        return null;
     651                    }
     652                }
    663653                sb.append(t);
    664654            } else if (type == Keyword.WILD) {
     
    21072097            } else {
    21082098                ZipEntry entry = jarFile.getEntry(entryPath);
    2109     if (entry == null) {
    2110         Debug.trace("Failed to get InputStream for "   
    2111         + "'" + getNamestring() + "'");
     2099                if (entry == null) {
     2100                    Debug.trace("Failed to get InputStream for "   
     2101                                + "'" + getNamestring() + "'");
    21122102                    // XXX should this be fatal?
    2113         Debug.assertTrue(false);
    2114     }
     2103                    Debug.assertTrue(false);
     2104                }
    21152105                try {
    21162106                    result = jarFile.getInputStream(entry);
     
    22812271                if (Utilities.isPlatformWindows) {
    22822272                    if (destination.isFile()) {
    2283       ZipCache.remove(destination);
     2273                        ZipCache.remove(destination);
    22842274                        destination.delete();
    22852275                    }
     
    23412331
    23422332    public URL toURL() throws MalformedURLException {
    2343   if(isURL()) {
    2344       return new URL(getNamestring());
    2345   } else {
    2346       return toFile().toURL();
    2347   }
     2333        if(isURL()) {
     2334            return new URL(getNamestring());
     2335        } else {
     2336            return toFile().toURL();
     2337        }
    23482338    }
    23492339
    23502340    public File toFile() {
    2351   if(!isURL()) {
    2352       return new File(getNamestring());
    2353   } else {
    2354       throw new RuntimeException(this + " does not represent a file");
    2355   }
     2341        if(!isURL()) {
     2342            return new File(getNamestring());
     2343        } else {
     2344            throw new RuntimeException(this + " does not represent a file");
     2345        }
    23562346    }
    23572347
  • trunk/abcl/test/lisp/abcl/jar-pathname.lisp

    r13024 r13026  
    342342  (:absolute "c" "d") "foo" "lisp")
    343343
     344(deftest jar-pathname.10
     345    (let ((s "jar:file:/foo/bar/a space/that!/this"))
     346      (equal s
     347             (namestring (pathname s))))
     348  t)
     349
     350(deftest jar-pathname.11
     351    (let ((s "jar:file:/foo/bar/a+space/that!/this"))
     352      (equal s
     353             (namestring (pathname s))))
     354  t)
     355
     356
    344357(deftest jar-pathname.match-p.1
    345358    (pathname-match-p "jar:file:/a/b/some.jar!/a/system/def.asd"
  • trunk/abcl/test/lisp/abcl/pathname-tests.lisp

    r13011 r13026  
    439439  t)
    440440
     441#+windows
     442(deftest pathname.windows.6
     443   (equal (pathname-device #p"z:/foo/bar") "z")
     444  t)
     445
     446#+windows
     447(deftest pathname.windows.7
     448    (equal (pathname-device #p"file:z:/foo/bar") "z")
     449  t)
     450
     451#+windows
     452(deftest pathname.windows.8
     453    (equal (pathname-device #p"zoo:/foo/bar") nil)
     454  t)
     455
    441456(deftest wild.1
    442457  (check-physical-pathname #p"foo.*" nil "foo" :wild)
Note: See TracChangeset for help on using the changeset viewer.