code: private static String parseRelativeURL(URL url, String spec) {
          String path = url.getPath();
          String result;
  
          int index = path.indexOf("!/");
          if (index == -1) {
              // The "jar" protocol requires that the path contain an entry path.
              // For backwards compatibility, we do not.  Instead, we just
              // canonicalize the base URL.
              try {
                  url = Utils.newURL(Utils.newURL(path), spec);
              } catch (MalformedURLException ex) {
                  throw new RuntimeException(ex);
              }
  
              result = url.toString();
          } else {
              String entry;
  
              if (spec.startsWith("/")) {
                  // This is an absolute entry path, so we ignore the existing
                  // entry path.
                  entry = canonicalize(spec);
              } else {
                  // Extract the existing entry path.
                  entry = path.substring(index + 1);
  
                  if (entry.endsWith("/")) {
                      // The entry ends with '/', so we can directly append the
                      // relative entry path.
                      entry = canonicalize(entry + spec);
                  } else if (entry.endsWith("/.")) {
                      // We don't want the logic below because "." is not a
                      // "true" basename.
                      entry = canonicalize(entry + '/' + spec);
                  } else {
                      // Strip off the basename with a ".." path segment and
                      // append the relative entry path.
                      entry = canonicalize(entry + "/../" + spec);
                  }
              }
  
              result = path.substring(0, index) + '!' + entry;
          }
          return result;
      }
docs: wsjar:file:/a/b!/d/e