protobuf.js
protobuf.js copied to clipboard
Fix: Allow absolute URLs as paths, e.g. for load()
When using protobuf.js in a browser, it's useful to be able to load proto files from other origins. But currently, path.normalize() mangles URLs by removing the second slash after the scheme (e.g. https://example.com/file.js becomes https:/example.com/file.js).
Fix that issue, and better integrate the existing UNC support, by introducing a new path.absolutePrefix() function that checks for all the various prefixes that indicate a path is absolute and returns the one it finds (if any). By including both slashes in the return value for URLs, we exclude them from the normalization logic.
Note that this almost certainly still isn't perfect, as URLs, UNC paths, and even Windows drive letters are all quite complex. But I don't have the time or project context to make a major change here.
Note that this fixes the same problem that #1820 does. I didn't notice that PR before making this one, although this one has the added benefit of supporting additional URL schemes and simplifying the UNC code too.