According to URL and URI definitions, after the scheme (or protocol) followed by colon (:), there is an optional authority (or hostname) component preceded by two slashes (//).
The File URI describes exactly how many slashes can be a part of the authority as:
A valid file URI must therefore begin with either file:/path (no hostname), file:///path (empty hostname), or file://hostname/path.
When parsing an iOS file URL which looks like this:
file:///Users/username/Library/Developer/CoreSimulator/Devices/00000000-0000-0000-0000-000000000000/data/Containers/Data/Application/00000000-0000-0000-0000-000000000000/Documents/Inbox/dummy.pdf
the parser incorrectly takes all 3 slashes as a host predecessor (due to protocol regex looking for ([\\/]{1,})?, so 1 or more slashes), and takes the Users as a host, and the rest (starting with /username) as the path.
To properly parse this file URL, only 2 slashes should be used as a host predecessor, while 3rd slash should be the beginning of a path (thus resulting with an empty host).
Exact issue that this is causing is that the host is lowercased, and toString function always uses 2 slashes when building the string, so parsing above file URL, and using toString on it results with:
file://users/username/Library/Developer/CoreSimulator/Devices/00000000-0000-0000-0000-000000000000/data/Containers/Data/Application/00000000-0000-0000-0000-000000000000/Documents/Inbox/dummy.pdf
which is an incorrect file URL on iOS, and cannot be accessed.
Changing the protocolre from /^([a-z][a-z0-9.+-]*:)?([\\/]{1,})?([\S\s]*)/i to /^([a-z][a-z0-9.+-]*:)?([\\/]{2})?([\S\s]*)/i (so that ([\\/]{2})? will take 0 or 2 slashes) fixes this issue.
According to URL and URI definitions, after the
scheme(orprotocol) followed by colon (:), there is an optionalauthority(orhostname) component preceded by two slashes (//).The File URI describes exactly how many slashes can be a part of the
authorityas:When parsing an iOS file URL which looks like this:
the parser incorrectly takes all 3 slashes as a
hostpredecessor (due to protocol regex looking for([\\/]{1,})?, so 1 or more slashes), and takes theUsersas ahost, and the rest (starting with/username) as the path.To properly parse this file URL, only 2 slashes should be used as a
hostpredecessor, while 3rd slash should be the beginning of a path (thus resulting with an emptyhost).Exact issue that this is causing is that the
hostis lowercased, andtoStringfunction always uses 2 slashes when building the string, so parsing above file URL, and usingtoStringon it results with:which is an incorrect file URL on iOS, and cannot be accessed.
Changing the
protocolrefrom/^([a-z][a-z0-9.+-]*:)?([\\/]{1,})?([\S\s]*)/ito/^([a-z][a-z0-9.+-]*:)?([\\/]{2})?([\S\s]*)/i(so that([\\/]{2})?will take 0 or 2 slashes) fixes this issue.