Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions packages/react-native/scripts/cocoapods/__tests__/utils-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,53 @@ def teardown
$RN_PLATFORMS = nil
end

# ===================== #
# TEST - localFileUri #
# ===================== #

def test_localFileUri_whenPathContainsUnicode_returnsEscapedFileUri
# Arrange
path = "/tmp/rn-unicode/💻dev/React-Core-prebuilt.tar.gz"

# Act
result = ReactNativePodsUtils.local_file_uri(path)

# Assert
assert_equal("file:///tmp/rn-unicode/%F0%9F%92%BBdev/React-Core-prebuilt.tar.gz", result)
end

def test_localFileUri_whenPathContainsSpaces_returnsEscapedFileUri
# Arrange
path = "/tmp/rn space/React Core.tar.gz"

# Act
result = ReactNativePodsUtils.local_file_uri(path)

# Assert
assert_equal("file:///tmp/rn%20space/React%20Core.tar.gz", result)
end

def test_localFileUri_whenPathContainsOnlyAscii_returnsFileUri
# Arrange
path = "/tmp/rn-ascii/React-Core-prebuilt.tar.gz"

# Act
result = ReactNativePodsUtils.local_file_uri(path)

# Assert
assert_equal("file:///tmp/rn-ascii/React-Core-prebuilt.tar.gz", result)
end

def test_localFileUri_whenPathContainsUnicode_withoutEscapingUriFileBuildRaises
# Arrange
path = "/tmp/rn-unicode/💻dev/React-Core-prebuilt.tar.gz"

# Act & Assert
assert_raise(URI::InvalidComponentError) do
URI::File.build(path: path).to_s
end
end

# ======================= #
# TEST - warnIfNotOnArm64 #
# ======================= #
Expand Down
6 changes: 3 additions & 3 deletions packages/react-native/scripts/cocoapods/rncore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def self.resolve_podspec_source()
if ENV["RCT_TESTONLY_RNCORE_TARBALL_PATH"]
abort_if_use_local_rncore_with_no_file()
rncore_log("Using local xcframework at #{ENV["RCT_TESTONLY_RNCORE_TARBALL_PATH"]}")
return {:http => "file://#{ENV["RCT_TESTONLY_RNCORE_TARBALL_PATH"]}" }
return {:http => ReactNativePodsUtils.local_file_uri(ENV["RCT_TESTONLY_RNCORE_TARBALL_PATH"]) }
end

if ENV["RCT_USE_PREBUILT_RNCORE"] == "1"
Expand Down Expand Up @@ -161,7 +161,7 @@ def self.podspec_source_download_prebuild_stable_tarball()
rncore_log(" #{Pathname.new(destinationRelease).relative_path_from(Pathname.pwd).to_s}")

return {:http => stable_tarball_url(@@react_native_version, :debug) } unless @@download_dsyms
return {:http => URI::File.build(path: destinationDebug).to_s }
return {:http => ReactNativePodsUtils.local_file_uri(destinationDebug) }
end

def self.podspec_source_download_prebuilt_nightly_tarball()
Expand Down Expand Up @@ -198,7 +198,7 @@ def self.podspec_source_download_prebuilt_nightly_tarball()
rncore_log(" #{Pathname.new(destinationDebug).relative_path_from(Pathname.pwd).to_s}")
rncore_log(" #{Pathname.new(destinationRelease).relative_path_from(Pathname.pwd).to_s}")
return {:http => nightly_tarball_url(@@react_native_version, :debug) } unless @@download_dsyms
return {:http => URI::File.build(path: destinationDebug).to_s }
return {:http => ReactNativePodsUtils.local_file_uri(destinationDebug) }
end

def self.process_dsyms(frameworkTarball, dSymsTarball)
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/scripts/cocoapods/rndependencies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def self.resolve_podspec_source()
if ENV["RCT_USE_LOCAL_RN_DEP"]
abort_if_use_local_rndeps_with_no_file()
rndeps_log("Using local xcframework at #{ENV["RCT_USE_LOCAL_RN_DEP"]}")
return {:http => "file://#{ENV["RCT_USE_LOCAL_RN_DEP"]}" }
return {:http => ReactNativePodsUtils.local_file_uri(ENV["RCT_USE_LOCAL_RN_DEP"]) }
end

if ENV["RCT_USE_RN_DEP"] && ENV["RCT_USE_RN_DEP"] == "1"
Expand Down
6 changes: 6 additions & 0 deletions packages/react-native/scripts/cocoapods/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@

require 'shellwords'
require 'digest'
require 'uri'

require_relative "./helpers.rb"
require_relative "./jsengine.rb"

# Utilities class for React Native Cocoapods
class ReactNativePodsUtils
# URI::File.build validates path components as ASCII, so escape the filesystem path first.
def self.local_file_uri(path)
URI::File.build(path: URI::DEFAULT_PARSER.escape(path)).to_s
end

def self.warn_if_not_on_arm64
if SysctlChecker.new().call_sysctl_arm64() == 1 && !Environment.new().ruby_platform().include?('arm64')
Pod::UI.warn 'Do not use "pod install" from inside Rosetta2 (x86_64 emulation on arm64).'
Expand Down
Loading