From 72f6093d9879b4ec860aff0d9db0bf15b7517ce3 Mon Sep 17 00:00:00 2001 From: Kevin Sylvestre Date: Sat, 2 Jan 2021 13:41:39 -0800 Subject: [PATCH] Use URI.open instead of open Using open via the following snippet: require 'open-uri' open('https//...') In ruby 2 results in the following deprecation warning: warning: calling URI.open via Kernel#open is deprecated call URI.open directly or use URI#open In ruby 3 results in the following exception: Errno::ENOENT (No such file or directory @ rb_sysopen - https://...) The fixes by calling open through URI. --- lib/react/server_rendering/webpacker_manifest_container.rb | 4 ++-- test/support/webpacker_helpers.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/react/server_rendering/webpacker_manifest_container.rb b/lib/react/server_rendering/webpacker_manifest_container.rb index 4f2ecfbc..421bf118 100644 --- a/lib/react/server_rendering/webpacker_manifest_container.rb +++ b/lib/react/server_rendering/webpacker_manifest_container.rb @@ -27,7 +27,7 @@ def find_asset(logical_path) asset_path = manifest.lookup(logical_path).to_s if asset_path.start_with?('http') # Get a file from the webpack-dev-server - dev_server_asset = open(asset_path).read + dev_server_asset = URI.open(asset_path).read # Remove `webpack-dev-server/client/index.js` code which causes ExecJS to 💥 dev_server_asset.sub!(CLIENT_REQUIRE, '//\0') dev_server_asset @@ -44,7 +44,7 @@ def find_asset(logical_path) ds = Webpacker.dev_server # Remove the protocol and host from the asset path. Sometimes webpacker includes this, sometimes it does not asset_path.slice!("#{ds.protocol}://#{ds.host_with_port}") - dev_server_asset = open("#{ds.protocol}://#{ds.host_with_port}#{asset_path}").read + dev_server_asset = URI.open("#{ds.protocol}://#{ds.host_with_port}#{asset_path}").read dev_server_asset.sub!(CLIENT_REQUIRE, '//\0') dev_server_asset else diff --git a/test/support/webpacker_helpers.rb b/test/support/webpacker_helpers.rb index d1d26cf9..eb2f6e8f 100644 --- a/test/support/webpacker_helpers.rb +++ b/test/support/webpacker_helpers.rb @@ -101,7 +101,7 @@ def dev_server_running? return false unless example_asset_path return false unless example_asset_path.start_with?('http://localhost:8080') begin - file = open('http://localhost:8080/packs/application.js') + file = URI.open('http://localhost:8080/packs/application.js') rescue StandardError => e file = nil end @@ -134,7 +134,7 @@ def dev_server_running? example_asset_path = manifest_data.values.first return false unless example_asset_path begin - file = open("#{ds.protocol}://#{ds.host}:#{ds.port}#{example_asset_path}") + file = URI.open("#{ds.protocol}://#{ds.host}:#{ds.port}#{example_asset_path}") rescue StandardError => e file = nil end