Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve URLs with more than one colon fails #507

Open
3 tasks done
GitToTheHub opened this issue Dec 7, 2021 · 1 comment
Open
3 tasks done

Resolve URLs with more than one colon fails #507

GitToTheHub opened this issue Dec 7, 2021 · 1 comment

Comments

@GitToTheHub
Copy link
Contributor

Bug Report

If I try to resolve something like http://localhost:8000/index.html i get an ENCODING_ERR because of these lines:

// sanity check for 'not:valid:filename' or '/not:valid:filename'
// file.spec.12 window.resolveLocalFileSystemURI should error (ENCODING_ERR) when resolving invalid URI with leading /.
if (!uri || uri.split(':').length > 2) {
setTimeout(function () {
fail(FileError.ENCODING_ERR);
}, 0);
return;
}

When i disable this code like i did here GitToTheHub#1, I can finally resolve urls like http://localhost:8000/index.html. Do someone know why these lines of code exist and if it's safe to remove them? I would make an PR without these lines, or by allowing maximum 2 colons.

Problem

What is expected to happen?

URLs like http://localhost:8000/index.html should resolve

What does actually happen?

The API throws ENCODING_ERR

Information

Just run the app in a browser and try to resolve http://localhost:8000/index.html.

Command or Code

resolveLocalFileSystemURL(
  "http://localhost:8000/index.html",
  (fileEntry) => {
    alert("URL successfully resolved! name=" + fileEntry.name);
  },
  (fileError) => {
    alert("URL could not be resolved: " + fileError.code);
  }
);

(Something to note: When i try to resolve a wrong url with my changed code, to allow more than one colon, the errorcallback will not be invoked)

Environment, Platform, Device

Browser platform, but this issue will occure in any other platform also.

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above
@peitschie
Copy link
Contributor

Just noting this change has bit me also. Prior to the v7 update with the changes to support the custom asset loading on Android, you could safely call resolveLocalFileSystemURL with the result of a Entry.toInternalURL() or similar as that would always return a file:// or cdvfile:// URL on android. Now, it's only safe to call this with something that comes from entry.nativeURL.

I've adapted my own code to use the .nativeURL entry instead... but, interesting to note.

In my use case, I need to take a file path and save to local storage, and then after a subsequent app restart I reload the data from the previously saved file. Previously I was storing the result of toInternalURL()... now I'm storing the result of .nativeURL isntead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants