Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-9282

Plugin File for Android seems to require trailing slash to identify a directory

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.1.0
    • None
    • cordova-plugin-file

    Description

      Looking at LocalFileSystemURL.java, lines 39~55

      ```java
      public static LocalFilesystemURL parse(Uri uri) {
      if (!FILESYSTEM_PROTOCOL.equals(uri.getScheme()))

      { return null; }
      String path = uri.getPath();
      if (path.length() < 1) { return null; }

      int firstSlashIdx = path.indexOf('/', 1);
      if (firstSlashIdx < 0)

      { return null; }

      String fsName = path.substring(1, firstSlashIdx);
      path = path.substring(firstSlashIdx);
      boolean isDirectory = path.charAt(path.length() - 1) == '/';
      return new LocalFilesystemURL(uri, fsName, path, isDirectory);
      }
      ```

      I found that operations on urls like cdvfile://localhost/persistent (without trailing slash) don't work because firstSlashIds < 0.

      Looking at line 53, Plugin file relies on trailing slash to know in advance if uri is a directory.

      I can't find any mention of that in the docs.

      I find that relying on trailing slashes to identify a directory imposes a burden for client code that must normalize all paths before calling any Plugin File function.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              adriano.digiovanni Adriano Di Giovanni
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: