zmxv / react-native-sound

React Native module for playing sound clips
MIT License
2.79k stars 748 forks source link

Escape basePath when bundleName contains spaces #628

Closed vaxxis closed 4 years ago

vaxxis commented 4 years ago

On Xcode 11 if you have a bundleName with a space (eg. "Test App") the bundle name will have a space (eg. "Test App.app"). Without escaping, the library is unable to load the sound file.

Solves issues: #64, #136

vaxxis commented 4 years ago

Hi Paul, thanks for your reply. Do you think we can safely merge di pr now?

YaoHuiJi commented 4 years ago

please merge this pr into master, thanks.

kolyuchii commented 4 years ago

Something is wrong with this escaping the whole file path.

I'm trying to load URL "https://firebasestorage.googleapis.com/v0/b/aloud-1587725478366.appspot.com/o/streams%2F4iEOxKrTQhaDG4CMIAvxyu28GTl1_eLGZ6u3NziN3YXXfZx78_%D0%9F%D1%80%D0%BE_%D0%B1%D0%B5%D0%BB%D1%8B_%D0%B1%D0%B5%D0%BB%D1%8B.aac?alt=media&token=1419c6d1-22df-4ee8-a1f5-9160a27261b0" but it fails with an error {"code": "ENSOSSTATUSERRORDOMAIN-10875", "domain": "NSOSStatusErrorDomain", "message": "The operation couldn’t be completed. (OSStatus error -10875.)", "nativeStackIOS": ["0 aLoud 0x0000000101c48e74 RCTJSErrorFromCodeMessageAndNSError + 152", "1 aLoud 0x0000000101c48d9c RCTJSErrorFromNSError + 264", "2 aLoud 0x0000000101b240ec -[RNSound prepare:withKey:withOptions:withCallback:] + 1664", "3 CoreFoundation 0x0000000183d01800 <redacted> + 144", "4 CoreFoundation 0x0000000183be33c0 <redacted> + 292", "5 CoreFoundation 0x0000000183be3ff4 <redacted> + 60", "6 aLoud 0x0000000101bd6efc -[RCTModuleMethod invokeWithBridge:module:arguments:] + 1860", "7 aLoud 0x0000000101bda930 _ZN8facebook5reactL11invokeInnerEP9RCTBridgeP13RCTModuleDatajRKN5folly7dynamicE + 648", "8 aLoud 0x0000000101bda4c8 _ZZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEiENK3$_0clEv + 144", "9 aLoud 0x0000000101bda42c ___ZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEi_block_invoke + 28", "10 libdispatch.dylib 0x00000001077436f4 _dispatch_call_block_and_release + 24", "11 libdispatch.dylib 0x0000000107744c78 _dispatch_client_callout + 16", "12 libdispatch.dylib 0x000000010774cbf4 _dispatch_lane_serial_drain + 712", "13 libdispatch.dylib 0x000000010774d8b4 _dispatch_lane_invoke + 456", "14 libdispatch.dylib 0x000000010775777c _dispatch_workloop_worker_thread + 1148", "15 libsystem_pthread.dylib 0x0000000183919114 _pthread_wqthread + 304", "16 libsystem_pthread.dylib 0x000000018391bcd4 start_wqthread + 4"], "userInfo": {}}

Usage:

this.player = new Sound( decodeURIComponent(this.url), '', (error) => {

I can fix this issue by changing this line NSString* fileNameEscaped = [fileName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; to this NSString* fileNameEscaped = fileName;

Also, I've found the stringByAddingPercentEscapesUsingEncoding is deprecated by Apple https://developer.apple.com/documentation/foundation/nsstring/1415058-stringbyaddingpercentescapesusin?language=objc

sfuqua commented 2 years ago

I don't understand why the ObjC layer needs to be responsible for encoding a URI. Can't you just call urlencode from the script layer? Shouldn't it be the caller's responsibility to generate URIs that will resolve successfully?

This commit breaks loading network files that are already % encoded.