From fe7f9bff08b7a5df93ee5cf375447600b33163ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E5=86=A0=E5=B3=B0?= Date: Thu, 15 May 2025 15:38:13 +0800 Subject: [PATCH] fix #552 --- Assets/YooAsset/Runtime/Utility/YooUtility.cs | 14 ++++++++++++++ .../WechatFileSystem/WechatFileSystem.cs | 9 +++++++++ 2 files changed, 23 insertions(+) diff --git a/Assets/YooAsset/Runtime/Utility/YooUtility.cs b/Assets/YooAsset/Runtime/Utility/YooUtility.cs index 1f12aa62..c8df5589 100644 --- a/Assets/YooAsset/Runtime/Utility/YooUtility.cs +++ b/Assets/YooAsset/Runtime/Utility/YooUtility.cs @@ -34,6 +34,20 @@ namespace YooAsset return str.Remove(index); //"assets/config/test.unity3d" --> "assets/config/test" } + /// + /// URL地址是否包含双斜杠 + /// 注意:只检查协议之后的部分 + /// + public static bool HasDoubleSlashes(string url) + { + if (url == null) + throw new ArgumentNullException(); + + int protocolIndex = url.IndexOf("://"); + string partToCheck = protocolIndex == -1 ? url : url.Substring(protocolIndex + 3); + return partToCheck.Contains("//") || partToCheck.Contains(@"\\"); + } + /// /// 合并路径 /// diff --git a/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionFileSystem/WechatFileSystem/WechatFileSystem.cs b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionFileSystem/WechatFileSystem/WechatFileSystem.cs index c789081a..9a1b5bbb 100644 --- a/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionFileSystem/WechatFileSystem/WechatFileSystem.cs +++ b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionFileSystem/WechatFileSystem/WechatFileSystem.cs @@ -198,6 +198,15 @@ internal class WechatFileSystem : IFileSystem RemoteServices = new WebRemoteServices(webRoot); } + // 检查URL双斜杠 + // 注意:双斜杠会导致微信插件加载文件失败,但网络请求又不返回失败! + { + var mainURL = RemoteServices.GetRemoteMainURL("test.bundle"); + var fallbackURL = RemoteServices.GetRemoteFallbackURL("test.bundle"); + if (PathUtility.HasDoubleSlashes(mainURL) || PathUtility.HasDoubleSlashes(fallbackURL)) + throw new Exception($"{nameof(RemoteServices)} returned URL contains double slashes. !"); + } + _fileSystemMgr = WX.GetFileSystemManager(); } public virtual void OnDestroy()