src/java.base/share/classes/sun/net/www/protocol/jar/Handler.java
changeset 48897 3f19b5965355
parent 47216 71c04702a3d5
child 58631 36c5e85b8597
equal deleted inserted replaced
48896:1e358cc5af98 48897:3f19b5965355
   139         }
   139         }
   140         // then figure out if the spec is
   140         // then figure out if the spec is
   141         // 1. absolute (jar:)
   141         // 1. absolute (jar:)
   142         // 2. relative (i.e. url + foo/bar/baz.ext)
   142         // 2. relative (i.e. url + foo/bar/baz.ext)
   143         // 3. anchor-only (i.e. url + #foo), which we already did (refOnly)
   143         // 3. anchor-only (i.e. url + #foo), which we already did (refOnly)
   144         boolean absoluteSpec = false;
   144         boolean absoluteSpec = spec.length() >= 4
   145         if (spec.length() >= 4) {
   145                 ? spec.regionMatches(true, 0, "jar:", 0, 4)
   146             absoluteSpec = spec.substring(0, 4).equalsIgnoreCase("jar:");
   146                 : false;
   147         }
       
   148         spec = spec.substring(start, limit);
   147         spec = spec.substring(start, limit);
   149 
   148 
   150         if (absoluteSpec) {
   149         if (absoluteSpec) {
   151             file = parseAbsoluteSpec(spec);
   150             file = parseAbsoluteSpec(spec);
   152         } else if (!refOnly) {
   151         } else if (!refOnly) {
   154 
   153 
   155             // Canonize the result after the bangslash
   154             // Canonize the result after the bangslash
   156             int bangSlash = indexOfBangSlash(file);
   155             int bangSlash = indexOfBangSlash(file);
   157             String toBangSlash = file.substring(0, bangSlash);
   156             String toBangSlash = file.substring(0, bangSlash);
   158             String afterBangSlash = file.substring(bangSlash);
   157             String afterBangSlash = file.substring(bangSlash);
   159             sun.net.www.ParseUtil canonizer = new ParseUtil();
   158             afterBangSlash = ParseUtil.canonizeString(afterBangSlash);
   160             afterBangSlash = canonizer.canonizeString(afterBangSlash);
       
   161             file = toBangSlash + afterBangSlash;
   159             file = toBangSlash + afterBangSlash;
   162         }
   160         }
   163         setURL(url, "jar", "", -1, file, ref);
   161         setURL(url, "jar", "", -1, file, ref);
   164     }
   162     }
   165 
   163 
   166     private String parseAbsoluteSpec(String spec) {
   164     private String parseAbsoluteSpec(String spec) {
   167         URL url = null;
   165         int index;
   168         int index = -1;
       
   169         // check for !/
   166         // check for !/
   170         if ((index = indexOfBangSlash(spec)) == -1) {
   167         if ((index = indexOfBangSlash(spec)) == -1) {
   171             throw new NullPointerException("no !/ in spec");
   168             throw new NullPointerException("no !/ in spec");
   172         }
   169         }
   173         // test the inner URL
   170         // test the inner URL
   174         try {
   171         try {
   175             String innerSpec = spec.substring(0, index - 1);
   172             String innerSpec = spec.substring(0, index - 1);
   176             url = new URL(innerSpec);
   173             new URL(innerSpec);
   177         } catch (MalformedURLException e) {
   174         } catch (MalformedURLException e) {
   178             throw new NullPointerException("invalid url: " +
   175             throw new NullPointerException("invalid url: " +
   179                                            spec + " (" + e + ")");
   176                                            spec + " (" + e + ")");
   180         }
   177         }
   181         return spec;
   178         return spec;
   191                                                "context url:" +
   188                                                "context url:" +
   192                                                url +
   189                                                url +
   193                                                ": no !/");
   190                                                ": no !/");
   194             }
   191             }
   195             ctxFile = ctxFile.substring(0, bangSlash);
   192             ctxFile = ctxFile.substring(0, bangSlash);
   196         }
   193         } else {
   197         if (!ctxFile.endsWith("/") && (!spec.startsWith("/"))){
       
   198             // chop up the last component
   194             // chop up the last component
   199             int lastSlash = ctxFile.lastIndexOf('/');
   195             int lastSlash = ctxFile.lastIndexOf('/');
   200             if (lastSlash == -1) {
   196             if (lastSlash == -1) {
   201                 throw new NullPointerException("malformed " +
   197                 throw new NullPointerException("malformed " +
   202                                                "context url:" +
   198                                                "context url:" +
   203                                                url);
   199                                                url);
   204             }
   200             } else if (lastSlash < ctxFile.length() - 1) {
   205             ctxFile = ctxFile.substring(0, lastSlash + 1);
   201                 ctxFile = ctxFile.substring(0, lastSlash + 1);
       
   202             }
   206         }
   203         }
   207         return (ctxFile + spec);
   204         return (ctxFile + spec);
   208     }
   205     }
   209 }
   206 }