Skip to content

Commit 3bbced3

Browse files
committed
Use verbatim string literals for F# directives
Use C# verbatim string literals (@"...") when composing F# script directives to avoid escaping issues with Windows paths. Updated #r, #load and #I generation to produce @"path" in FSharpKernel.cs, NuGetReferenceProcessor.cs and ScriptDirectiveProcessor.cs so embedded file paths are handled correctly.
1 parent f6ed52d commit 3bbced3

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

src/Verso.FSharp/Kernel/FSharpKernel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public Task InitializeAsync()
150150
var abstractionsAssembly = typeof(Verso.Abstractions.IVariableStore).Assembly.Location;
151151
if (!string.IsNullOrEmpty(abstractionsAssembly))
152152
{
153-
_sessionManager.EvalSilent($"#r \"{abstractionsAssembly}\"");
153+
_sessionManager.EvalSilent($"#r @\"{abstractionsAssembly}\"");
154154
}
155155

156156
_variableBridge = new VariableBridge(_options);
@@ -216,7 +216,7 @@ public async Task<IReadOnlyList<CellOutput>> ExecuteAsync(string code, IExecutio
216216
var magicPaths = _nugetProcessor!.CheckMagicCommandResults(context.Variables);
217217
foreach (var path in magicPaths)
218218
{
219-
_sessionManager!.EvalSilent($"#r \"{path}\"");
219+
_sessionManager!.EvalSilent($"#r @\"{path}\"");
220220
_projectContext?.AddReference(path);
221221
var dir = Path.GetDirectoryName(path);
222222
if (dir is not null)

src/Verso.FSharp/NuGet/NuGetReferenceProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public async Task<NuGetProcessResult> ProcessAsync(
133133
if (_resolvedAssemblyPaths.Add(assemblyPath))
134134
{
135135
newPaths.Add(assemblyPath);
136-
session.EvalSilent($"#r \"{assemblyPath}\"");
136+
session.EvalSilent($"#r @\"{assemblyPath}\"");
137137
var dir = Path.GetDirectoryName(assemblyPath);
138138
if (dir is not null)
139139
session.AddNuGetAssemblyDirectory(dir);

src/Verso.FSharp/NuGet/ScriptDirectiveProcessor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public string ProcessDirectives(string code, INotebookMetadata? metadata)
6161
var resolved = ResolvePath(relativePath, metadata);
6262
if (File.Exists(resolved) && !_resolvedAssemblyPaths.Contains(resolved))
6363
_resolvedAssemblyPaths.Add(resolved);
64-
return $"#r \"{resolved}\"";
64+
return $"#r @\"{resolved}\"";
6565
});
6666

6767
// Process #load "script.fsx"
@@ -71,15 +71,15 @@ public string ProcessDirectives(string code, INotebookMetadata? metadata)
7171
var resolved = ResolvePath(relativePath, metadata);
7272
if (File.Exists(resolved) && !_loadedFilePaths.Contains(resolved))
7373
_loadedFilePaths.Add(resolved);
74-
return $"#load \"{resolved}\"";
74+
return $"#load @\"{resolved}\"";
7575
});
7676

7777
// Process #I "path"
7878
processed = IncludePathRegex.Replace(processed, match =>
7979
{
8080
var relativePath = match.Groups[1].Value;
8181
var resolved = ResolvePath(relativePath, metadata);
82-
return $"#I \"{resolved}\"";
82+
return $"#I @\"{resolved}\"";
8383
});
8484

8585
// Process #nowarn "number"

0 commit comments

Comments
 (0)