Skip to content

feat: implement JavaScript string escaping for environment variables and add unit tests - #1059

Merged
jeromelaban merged 4 commits into
mainfrom
dev/gl/escape-env-var
Apr 8, 2026
Merged

jeromelaban merged 4 commits into
mainfrom
dev/gl/escape-env-var

Conversation

@GabrielLaban

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI review requested due to automatic review settings April 8, 2026 14:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements JavaScript string escaping when emitting environment variables into uno-config.js, and adds unit tests for the escaping behavior.

Changes:

  • Escape environment variable values during config generation (GenerateConfig).
  • Introduce EscapeJsString helper to perform escaping.
  • Add MSTest coverage validating escaping for quotes and backslashes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/Uno.Wasm.Bootstrap/ShellTask.cs Escapes emitted env-var values in generated JS config and adds an escaping helper.
src/Uno.Wasm.Bootstrap.UnitTests/Given_ShellTask_EnvironmentVariableEscaping.cs Adds unit tests covering the escaping helper’s current behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Uno.Wasm.Bootstrap/ShellTask.cs Resolved
Comment thread src/Uno.Wasm.Bootstrap/ShellTask.cs Resolved
Copilot AI review requested due to automatic review settings April 8, 2026 18:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

src/Uno.Wasm.Bootstrap/ShellTask.cs:605

  • The environment variable name is interpolated into a JS string literal without escaping. If a MonoEnvironment item spec ever contains \ or " (or other special chars), the generated uno-config.js will be syntactically invalid or could be subject to code injection. Consider escaping name with the same JS-string escaping routine (or emitting both name/value using a JSON string literal).
				config.AppendLine($"config.environmentVariables = config.environmentVariables || {{}};");

				void AddEnvironmentVariable(string name, string value) => config.AppendLine($"config.environmentVariables[\"{name}\"] = \"{EscapeJsString(value)}\";");

				if (MonoEnvironment != null)
				{
					foreach (var env in MonoEnvironment)
					{
						AddEnvironmentVariable(env.ItemSpec, env.GetMetadata("Value"));
					}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jeromelaban
jeromelaban enabled auto-merge April 8, 2026 20:29
@jeromelaban
jeromelaban merged commit d7e2344 into main Apr 8, 2026
10 of 11 checks passed
@jeromelaban
jeromelaban deleted the dev/gl/escape-env-var branch April 8, 2026 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants