Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Escaping urls for remote assets

Discussion in 'Addressables' started by aixa, Nov 1, 2022.

  1. aixa

    aixa

    Joined:
    Sep 28, 2012
    Posts:
    46
    Hi, we have been having a bit of trouble with addressable recently and found out that the URL was incorrect when fetching assets from remote CDN. I don't remember having this issue in previous versions.

    The reason was double escaping.
    In our setup we use dynamic location for the assets that come from our backend. Backend provides already escaped URLs. Also we could only report this issue on iOS and Android, so it was harder to figure out.

    Is there any reason why in AssetBundleProvider.cs when creating webRequest you have this code?
    Code (CSharp):
    1. #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
    2.             Uri uri = new Uri(url.Replace(" ", "%20"));
    3. #else
    4.             Uri uri = new Uri(Uri.EscapeUriString(url));
    5. #endif
    6.  
    Is there any better way than unescaping the URL on Addressables.InternalIdTransformFunc?:)
     
    Dasp likes this.
  2. Dasp

    Dasp

    Joined:
    Sep 25, 2012
    Posts:
    38
  3. aixa

    aixa

    Joined:
    Sep 28, 2012
    Posts:
    46
    We still have the problem with the newer addressable package
    In addition, there is a problem with testing as an editor has different behavior than the simulated platform.
    Addressable.InternalIdTransformFunc does not really work for us, as there is not a reliable way to know which URL we should transform.
    Any help?
     
  4. paezguerraalvaro

    paezguerraalvaro

    Joined:
    Oct 16, 2017
    Posts:
    9
    I just got hit by this same issue after upgrading to v2022, which caused the Addressables package to be updated as well. In our specific use case we need some of the URL's forward slashes to be escaped into %2F, due to how Firebase interprets them. We do this in our own Addressables.InternalIdTransformFunc, but it results in the URL being escaped twice. The only solution I have found is to embed the package and remove the escaping in the AssetBundleProvider. I'm not sure what the proper solution is, maybe disabling any escaping if the url has been obtained from a custom transform function.
    I don't understand why the package is using EscapeUriString, either, as it's clearly marked as obsolete.
     
  5. Dasp

    Dasp

    Joined:
    Sep 25, 2012
    Posts:
    38
    bump, we would like to fix this issue
     
  6. Dasp

    Dasp

    Joined:
    Sep 25, 2012
    Posts:
    38
    @davidla_unity could we get some insight why EscapeUriString is used in there? All firebase users will be affected by it.
     
  7. pillakirsten

    pillakirsten

    Unity Technologies

    Joined:
    May 22, 2019
    Posts:
    346
  8. Dasp

    Dasp

    Joined:
    Sep 25, 2012
    Posts:
    38
    Thank you for the information we will try that.
     
  9. SharpAccent

    SharpAccent

    Joined:
    Jul 19, 2018
    Posts:
    39
    is this been resolved? i'm still facing the same issue in 2021.3.25f1
     
  10. elfasito

    elfasito

    Joined:
    Jul 4, 2017
    Posts:
    51
    bump, waiting of updates of this issue...
     
  11. SharpAccent

    SharpAccent

    Joined:
    Jul 19, 2018
    Posts:
    39
    in my case i did as suggested


    Code (CSharp):
    1.             Addressables.WebRequestOverride = EditWebRequestURL;
    2.  
    3.  
    4. private void EditWebRequestURL(UnityWebRequest obj)
    5.         {
    6.             if (obj.url.Contains("%20"))
    7.             {
    8.                 obj.url.Replace("%20", "");
    9.             }
    10.         }
    works well so far but you need to be careful not to include spaces anywhere in your urls
     
  12. elfasito

    elfasito

    Joined:
    Jul 4, 2017
    Posts:
    51
    @SharpAccent Thanks, it works.
    in my case I need modify it a bit:
    Code (CSharp):
    1. obj.url.Replace("%20", "");
    to:
    Code (CSharp):
    1. obj.url = obj.url.Replace("%20", "");
    because not was replacing it.
     
  13. elfasito

    elfasito

    Joined:
    Jul 4, 2017
    Posts:
    51
    sorry for necro this, but still im struggling with this.
    I hope newest versions of addressables disable or make optionally this scaping of urls. but no...

    I edited AsetBundleProvider.cs to something like this:
    Code (CSharp):
    1. #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
    2.             Uri uri = new Uri(url.Replace(" ", "%20"));
    3. #else
    4.             string uri = url; //use this for android build
    5. #endif

    but only works for the first time the bundle is downloaded, when it try to load from cache just stuck on loading.

    PS: the above solution which I said worked (my previous reply), have the same problem, only works for the first time I download the bundle.
    the last version of addressables working for me its 1.19.19