Skip to content

Commit 40dcdcb

Browse files
authored
[nativeaot] fix Java string escaping and logging in environment variables support code (#10771)
This PR applies review feedback from the backport PR #10768 to the main branch, addressing three improvements to the NativeAOT environment variable handling: **Changes:** - Fixed Java string escaping in `EnvironmentBuilder.cs` to properly escape backslashes before quotes, preventing invalid Java string literals - Added missing `$` prefix for string interpolation in a test assertion message in `EnvironmentHelper.cs` - Enhanced error logging in `NativeAotEnvironmentVars.java` to include exception details when environment variable setting fails
1 parent 827a790 commit 40dcdcb

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

src/Xamarin.Android.Build.Tasks/Resources/NativeAotEnvironmentVars.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static void Initialize ()
3232
Os.setenv (envNames[i], envValues[i], true /* overwrite */);
3333
}
3434
} catch (ErrnoException e) {
35-
Log.e (TAG, "Failed to set environment variables");
35+
Log.e (TAG, "Failed to set environment variables", e);
3636
}
3737
}
3838
}

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/EnvironmentHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ public static Dictionary<string, string> ReadNativeAotEnvironmentVariables (stri
842842
}
843843
}
844844

845-
Assert.AreEqual (names.Count, values.Count, "Environment variable name and value arrays aren't of the same size in '{javaSourcePath}'");
845+
Assert.AreEqual (names.Count, values.Count, $"Environment variable name and value arrays aren't of the same size in '{javaSourcePath}'");
846846
for (int i = 0; i < names.Count; i++) {
847847
ret.Add (names[i], values[i]);
848848
}

src/Xamarin.Android.Build.Tasks/Utilities/EnvironmentBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,5 @@ public void AddMonoGcParams (bool enableSgenConcurrent)
108108
AddEnvironmentVariable ("MONO_GC_PARAMS", enableSgenConcurrent ? "major=marksweep-conc" : "major=marksweep");
109109
}
110110

111-
static string ValidAssemblerString (string s) => s.Replace ("\"", "\\\"");
111+
static string ValidAssemblerString (string s) => s.Replace ("\\", "\\\\").Replace ("\"", "\\\"");
112112
}

0 commit comments

Comments
 (0)