Skip to content

Rewrite your app in Rust, piece by piece, checked against the original at every step. Works with TypeScript, JavaScript, Python, Go, Ruby, Java, C, PHP, C#, Kotlin, PowerShell and Swift.

Ruby: count Dir.tmpdir, Socket.gethostname and Process.pid as environment reads (#1417)

jakalijeyf9fc9f8d2bf0
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 20c5bf99..2421490f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -267,6 +267,9 @@
- PowerShell: a parameter typed `[decimal]`, `[uint64]` or `[ulong]` keeps its function in
PowerShell, with the reasons C# gives for the same types, instead of bridging it as `f64` or
`i64`. `[uint32]`, `[double]` and `[single]` bridge as before (#1341 by @jakalijey).
+- Ruby: `Dir.tmpdir`, `Dir.mktmpdir`, `Socket.gethostname`, `Process.pid`, `Process.uid` and
+ `Gem.user_home` count as reading the environment, as `Dir.home` already did, in `analyze` and
+ `bridge` (#1411 by @jakalijey).
- Go: `os.ExpandEnv`, `os.TempDir`, `os.UserConfigDir`, `os.UserCacheDir` and `os.Executable`
count as reading the environment, as `os.Getenv` and `os.UserHomeDir` already did, in `analyze`
and `bridge` (#1405 by @jakalijey).
diff --git a/src/lang/effects.rs b/src/lang/effects.rs
index a561f488..2037f19a 100644
--- a/src/lang/effects.rs
+++ b/src/lang/effects.rs
@@ -177,7 +177,19 @@ fn environment(lang: Lang) -> &'static [&'static str] {
"System.getProperties(",
"InetAddress.getLocalHost(",
],
- Lang::Ruby => &["ENV[", "ENV.", "Dir.pwd", "Dir.home", "Etc."],
+ Lang::Ruby => &[
+ "ENV[",
+ "ENV.",
+ "Dir.pwd",
+ "Dir.home",
+ "Etc.",
+ "Dir.tmpdir",
+ "Dir.mktmpdir",
+ "Socket.gethostname",
+ "Process.pid",
+ "Process.uid",
+ "Gem.user_home",
+ ],
Lang::Php => &["getenv(", "$_ENV", "$_SERVER", "getcwd(", "gethostname("],
Lang::Csharp => &[
"Environment.GetEnvironmentVariable",
@@ -1493,6 +1505,8 @@ mod tests {
"String f(String x){ return System.getenv(\"HOME\") + x; }",
),
(Lang::Ruby, "def self.f(x)\n ENV.fetch('HOME') + x\nend"),
+ (Lang::Ruby, "def self.f(x)\n File.join(Dir.tmpdir, x)\nend"),
+ (Lang::Ruby, "def self.f(x)\n Socket.gethostname + x\nend"),
(Lang::Php, "function f($x) { return getenv('HOME') . $x; }"),
(Lang::Powershell, "function F { param($X) $env:HOME + $X }"),
(