diff --git a/src/QsCompiler/CompilationManager/CompilationUnitManager.cs b/src/QsCompiler/CompilationManager/CompilationUnitManager.cs
index 8dc0e3f635..2cda5999be 100644
--- a/src/QsCompiler/CompilationManager/CompilationUnitManager.cs
+++ b/src/QsCompiler/CompilationManager/CompilationUnitManager.cs
@@ -145,14 +145,34 @@ public void Dispose()
// routines related to tracking the source files
///
- /// Returns the string with the file ID associated with the given URI used throughout the compilation.
+ /// Converts a URI into the file ID used during compilation if the URI is an absolute file URI.
///
- public static bool TryGetFileId(Uri uri, out NonNullable id)
+ /// Thrown if the URI is null.
+ /// Thrown if the URI is not an absolute URI or not a file URI.
+ public static NonNullable GetFileId(Uri uri) =>
+ uri is null
+ ? throw new ArgumentNullException(nameof(uri))
+ : TryGetFileId(uri, out var fileId)
+ ? fileId
+ : throw new ArgumentException("The URI is not an absolute file URI.", nameof(uri));
+
+ ///
+ /// Converts a URI into the file ID used during compilation if the URI is an absolute file URI.
+ ///
+ /// True if converting the URI to a file ID succeeded.
+ [Obsolete("Use GetFileId instead after ensuring that the URI is an absolute file URI.")]
+ public static bool TryGetFileId(Uri uri, out NonNullable fileId)
{
- id = NonNullable.New("");
- if (uri == null || !uri.IsFile || !uri.IsAbsoluteUri) return false;
- id = NonNullable.New(uri.IsUnc ? uri.LocalPath : uri.AbsolutePath);
- return true;
+ if (!(uri is null) && uri.IsFile && uri.IsAbsoluteUri)
+ {
+ fileId = NonNullable.New(uri.LocalPath);
+ return true;
+ }
+ else
+ {
+ fileId = default;
+ return false;
+ }
}
///
diff --git a/src/QsCompiler/TestTargets/Libraries/Library1/Library1.csproj b/src/QsCompiler/TestTargets/Libraries/Library1/Library1.csproj
index 0fd94350fe..c29fbc8350 100644
--- a/src/QsCompiler/TestTargets/Libraries/Library1/Library1.csproj
+++ b/src/QsCompiler/TestTargets/Libraries/Library1/Library1.csproj
@@ -6,7 +6,7 @@
-
+
diff --git a/src/QsCompiler/TestTargets/Libraries/Library2/Library2.csproj b/src/QsCompiler/TestTargets/Libraries/Library2/Library2.csproj
index 40d3dae54b..2a7c71b7d2 100644
--- a/src/QsCompiler/TestTargets/Libraries/Library2/Library2.csproj
+++ b/src/QsCompiler/TestTargets/Libraries/Library2/Library2.csproj
@@ -6,7 +6,7 @@
-
+
diff --git a/src/QsCompiler/TestTargets/Simulation/Target/Simulation.csproj b/src/QsCompiler/TestTargets/Simulation/Target/Simulation.csproj
index 7359dc8a41..6b5cd19d8c 100644
--- a/src/QsCompiler/TestTargets/Simulation/Target/Simulation.csproj
+++ b/src/QsCompiler/TestTargets/Simulation/Target/Simulation.csproj
@@ -13,7 +13,7 @@
-
+
diff --git a/src/QsCompiler/Tests.Compiler/SerializationTests.fs b/src/QsCompiler/Tests.Compiler/SerializationTests.fs
index c48e8f233d..b8d546cd6b 100644
--- a/src/QsCompiler/Tests.Compiler/SerializationTests.fs
+++ b/src/QsCompiler/Tests.Compiler/SerializationTests.fs
@@ -35,9 +35,8 @@ module SerializationTests =
open System
open System.Collections.Immutable
- open System.IO;
open System.Reflection
- open System.Reflection.PortableExecutable;
+ open System.Web
open Microsoft.Quantum.QsCompiler
open Microsoft.Quantum.QsCompiler.CompilationBuilder
open Microsoft.Quantum.QsCompiler.DataTypes
@@ -261,7 +260,8 @@ module SerializationTests =
let specs = attrs.Specializations |> Seq.map (fun s -> (s.ToTuple() |> fst).ToJson()) |> Seq.toList
let AssertEqual (expected : string list) (got : _ list) =
Assert.Equal(expected.Length, got.Length)
- expected |> List.iteri (fun i ex -> Assert.Equal (ex.Replace("%%%", dllId.Value), got.[i]))
+ expected |> List.iteri (fun i ex ->
+ Assert.Equal (ex.Replace("%%%", HttpUtility.JavaScriptStringEncode dllId.Value), got.[i]))
AssertEqual [CALLABLE_1; CALLABLE_2; CALLABLE_3] callables
AssertEqual [SPECIALIZATION_1; SPECIALIZATION_3] specs
AssertEqual [TYPE_1] types
@@ -275,6 +275,3 @@ module SerializationTests =
[]
[]
do ()
-
-
-