diff --git a/driver/js/src/napi/jsc/jsc_ctx.cc b/driver/js/src/napi/jsc/jsc_ctx.cc index c7d1be501ce..25f1d9f8a83 100644 --- a/driver/js/src/napi/jsc/jsc_ctx.cc +++ b/driver/js/src/napi/jsc/jsc_ctx.cc @@ -1149,6 +1149,7 @@ std::shared_ptr JSCCtx::RunScript(const string_view& data, if (exception) { SetException(std::make_shared(context_, exception)); + FOOTSTONE_LOG(ERROR) << GetExceptionMessage(exception_); return nullptr; } diff --git a/framework/ios/base/bridge/HippyBridge.h b/framework/ios/base/bridge/HippyBridge.h index a19b26df1af..4b5b9e18212 100644 --- a/framework/ios/base/bridge/HippyBridge.h +++ b/framework/ios/base/bridge/HippyBridge.h @@ -94,7 +94,7 @@ HIPPY_EXTERN NSString *HippyBridgeModuleNameForClass(Class bridgeModuleClass); /// /// Note: 多个bridge使用相同的共享engineKey时,只有全部bridge实例销毁时engine资源才将释放,因此,请注意合理使用,避免出现意外的内存泄漏。 /// 传空时默认不共享,SDK内部默认分配一随机key。 -- (instancetype)initWithDelegate:(id)delegate +- (instancetype)initWithDelegate:(nullable id)delegate moduleProvider:(nullable HippyBridgeModuleProviderBlock)block launchOptions:(nullable NSDictionary *)launchOptions executorKey:(nullable NSString *)executorKey; @@ -112,7 +112,7 @@ HIPPY_EXTERN NSString *HippyBridgeModuleNameForClass(Class bridgeModuleClass); /// /// Note: 多个bridge使用相同的共享engineKey时,只有全部bridge实例销毁时engine资源才将释放,因此,请注意合理使用,避免出现意外的内存泄漏。 /// 传空时默认不共享,SDK内部默认分配一随机key。 -- (instancetype)initWithDelegate:(id)delegate +- (instancetype)initWithDelegate:(nullable id)delegate bundleURL:(nullable NSURL *)bundleURL moduleProvider:(nullable HippyBridgeModuleProviderBlock)block launchOptions:(nullable NSDictionary *)launchOptions diff --git a/hippy.podspec b/hippy.podspec index 1d5142f4c90..3b48f1bbab1 100644 --- a/hippy.podspec +++ b/hippy.podspec @@ -167,6 +167,7 @@ Pod::Spec.new do |s| 'GCC_ENABLE_CPP_EXCEPTIONS' => false, 'GCC_ENABLE_CPP_RTTI' => false, } + iosvfs.dependency 'hippy/Base' iosvfs.dependency 'hippy/VFS' iosvfs.dependency 'hippy/Footstone' iosvfs.dependency 'hippy/FootstoneUtils' diff --git a/modules/ios/base/HippyDefines.h b/modules/ios/base/HippyDefines.h index 2b12aff1569..46b32e34a82 100644 --- a/modules/ios/base/HippyDefines.h +++ b/modules/ios/base/HippyDefines.h @@ -85,6 +85,16 @@ method NS_UNAVAILABLE { _Pragma("clang diagnostic pop") +#pragma mark - Clang Warnings + +// warning list ref:https://clang.llvm.org/docs/DiagnosticsReference.html +#define HIPPY_CLANG_WARN_CONCAT(warning_name) HIPPY_STR_EXPAND(clang diagnostic ignored warning_name) +#define HIPPY_IGNORE_WARNING_BEGIN(warningName) _Pragma("clang diagnostic push") _Pragma(HIPPY_CLANG_WARN_CONCAT(#warningName)) +#define HIPPY_IGNORE_WARNING_END _Pragma("clang diagnostic pop") + + +#pragma mark - + #define HIPPY_VERSION_3_0 300 diff --git a/modules/ios/base/HippyUtils.m b/modules/ios/base/HippyUtils.m index e257b5a0cc7..448fea984c1 100644 --- a/modules/ios/base/HippyUtils.m +++ b/modules/ios/base/HippyUtils.m @@ -438,15 +438,7 @@ static void HPGetRGBAColorComponents(CGColorRef color, CGFloat rgba[4]) { if (nil == uriData) { return nil; } - CFURLRef urlRef = NULL; - if ([URLString hasPrefix:@"http"] || - [URLString hasPrefix:@"data:"] || - [URLString hasPrefix:@"file:"]) { - urlRef = CFURLCreateWithBytes(NULL, [uriData bytes], [uriData length], kCFStringEncodingUTF8, (__bridge CFURLRef)baseURL); - } - else { - urlRef = CFURLCreateWithFileSystemPath(NULL, (__bridge CFStringRef)URLString, kCFURLPOSIXPathStyle, NO); - } + CFURLRef urlRef = CFURLCreateWithBytes(NULL, [uriData bytes], [uriData length], kCFStringEncodingUTF8, (__bridge CFURLRef)baseURL); NSURL *source_url = CFBridgingRelease(urlRef); return source_url; } diff --git a/modules/vfs/ios/VFSUriLoader.mm b/modules/vfs/ios/VFSUriLoader.mm index 0825443c4ba..d4c6ccda1c2 100644 --- a/modules/vfs/ios/VFSUriLoader.mm +++ b/modules/vfs/ios/VFSUriLoader.mm @@ -25,10 +25,9 @@ #import "TypeConverter.h" #import "VFSUriLoader.h" #import "VFSUriHandler.h" - +#import "HippyAssert.h" #include #include - #include "footstone/string_view_utils.h" NSString *const VFSErrorDomain = @"VFSErrorDomain"; @@ -91,7 +90,9 @@ NSOperationQueue *operationQueue, VFSHandlerProgressBlock progress, VFSHandlerCompletionBlock completion) { - NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]; + NSURL *url = HippyURLWithString(urlString, nil); + HippyAssert(url, @"Invalid URL! %@", urlString); + NSURLRequest *request = [NSURLRequest requestWithURL:url]; RequestUntrustedContent(request, extraInfo, operationQueue, progress, completion); } diff --git a/tests/ios/HippyUtilsTest.m b/tests/ios/HippyUtilsTest.m new file mode 100644 index 00000000000..fb41d388923 --- /dev/null +++ b/tests/ios/HippyUtilsTest.m @@ -0,0 +1,90 @@ +/*! + * iOS SDK + * + * Tencent is pleased to support the open source community by making + * Hippy available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import +#import + +@interface HippyUtilsTest : XCTestCase + +@end + +@implementation HippyUtilsTest + +- (void)setUp { + // Put setup code here. This method is called before the invocation of each test method in the class. +} + +- (void)tearDown { + // Put teardown code here. This method is called after the invocation of each test method in the class. +} + +- (void)testSDKVersionExists { + NSString *ver = [HippyUtils sdkVersion]; + XCTAssertNotNil(ver); +} + +- (void)testHippyURLWithString { + HIPPY_IGNORE_WARNING_BEGIN(-Wnonnull) + XCTAssertNil(HippyURLWithString(nil, nil)); + HIPPY_IGNORE_WARNING_END + XCTAssert([[HippyURLWithString(@"", nil) absoluteString] length] == 0); + + NSArray *testPaths = @[ + @"http://hippyjs.org", + @"https://hippyjs.org", + @"file:///testAbsulotePath/subPath", + @"hpfile://./testHippyRelativePath/subPath", + @"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAA", + // Some exceptions, such as Spaces or newlines + @"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAA\n\n ", + ]; + for (NSString *path in testPaths) { + NSURL *url = HippyURLWithString(path, nil); + XCTAssertNotNil(url); + NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO]; + XCTAssertNotNil(components.scheme); + XCTAssertNotNil(components.path); + } + testPaths = @[ + @"测试中文", + ]; + for (NSString *path in testPaths) { + NSURL *url = HippyURLWithString(path, nil); + XCTAssertNotNil(url); + NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO]; + XCTAssertNil(components.scheme); + XCTAssertNotNil(components.path); + } + + NSString *baseUrl = @"https://hippyjs.org/#/"; + testPaths = @[ + @"hello/hippy", + ]; + for (NSString *path in testPaths) { + NSURL *url = HippyURLWithString(path, baseUrl); + XCTAssert([url.absoluteString isEqualToString:@"https://hippyjs.org/hello/hippy"]); + } + +} + + +@end