Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,14 @@ private List<Target> ReadTargets(ref Utf8JsonReader reader)

while (reader.Read() && reader.IsTokenTypeProperty())
{
targets.Add(ReadTarget(ref reader, reader.GetString()!));
string? targetName = reader.GetString();

if (string.IsNullOrEmpty(targetName))
{
throw new FormatException(SR.Format(SR.RequiredFieldNotSpecified, nameof(targetName)));
}

targets.Add(ReadTarget(ref reader, targetName));
}

reader.CheckEndObject();
Expand All @@ -374,7 +381,14 @@ private Target ReadTarget(ref Utf8JsonReader reader, string targetName)

while (reader.Read() && reader.IsTokenTypeProperty())
{
libraries.Add(ReadTargetLibrary(ref reader, reader.GetString()!));
string? targetLibraryName = reader.GetString();

if (string.IsNullOrEmpty(targetLibraryName))
{
throw new FormatException(SR.Format(SR.RequiredFieldNotSpecified, nameof(targetLibraryName)));
}

libraries.Add(ReadTargetLibrary(ref reader, targetLibraryName));
}

reader.CheckEndObject();
Expand Down Expand Up @@ -448,7 +462,16 @@ private IEnumerable<Dependency> ReadTargetLibraryDependencies(ref Utf8JsonReader

while (reader.TryReadStringProperty(out string? name, out string? version))
{
dependencies.Add(new Dependency(Pool(name)!, Pool(version)!));
if (string.IsNullOrEmpty(name))
{
throw new FormatException(SR.Format(SR.RequiredFieldNotSpecified, nameof(name)));
}
if (string.IsNullOrEmpty(version))
{
throw new FormatException(SR.Format(SR.RequiredFieldNotSpecified, nameof(version)));
}

dependencies.Add(new Dependency(Pool(name), Pool(version)));
}

reader.CheckEndObject();
Expand All @@ -464,7 +487,12 @@ private static List<string> ReadPropertyNames(ref Utf8JsonReader reader)

while (reader.Read() && reader.IsTokenTypeProperty())
{
string libraryName = reader.GetString()!;
string? libraryName = reader.GetString();

if (string.IsNullOrEmpty(libraryName))
{
throw new FormatException(SR.Format(SR.RequiredFieldNotSpecified, nameof(libraryName)));
}
reader.Skip();

runtimes.Add(libraryName);
Expand All @@ -486,7 +514,12 @@ private static List<RuntimeFile> ReadRuntimeFiles(ref Utf8JsonReader reader)
string? assemblyVersion = null;
string? fileVersion = null;

string path = reader.GetString()!;
string? path = reader.GetString();

if (string.IsNullOrEmpty(path))
{
throw new FormatException(SR.Format(SR.RequiredFieldNotSpecified, nameof(path)));
}

reader.ReadStartObject();

Expand Down Expand Up @@ -521,9 +554,16 @@ private List<RuntimeTargetEntryStub> ReadTargetLibraryRuntimeTargets(ref Utf8Jso

while (reader.Read() && reader.IsTokenTypeProperty())
{
string? runtimePath = reader.GetString();

if (string.IsNullOrEmpty(runtimePath))
{
throw new FormatException(SR.Format(SR.RequiredFieldNotSpecified, nameof(runtimePath)));
}

var runtimeTarget = new RuntimeTargetEntryStub
{
Path = reader.GetString()!
Path = runtimePath
};

reader.ReadStartObject();
Expand Down Expand Up @@ -565,7 +605,13 @@ private List<ResourceAssembly> ReadTargetLibraryResources(ref Utf8JsonReader rea

while (reader.Read() && reader.IsTokenTypeProperty())
{
string path = reader.GetString()!;
string? path = reader.GetString();

if (string.IsNullOrEmpty(path))
{
throw new FormatException(SR.Format(SR.RequiredFieldNotSpecified, nameof(path)));
}

string? locale = null;

reader.ReadStartObject();
Expand Down Expand Up @@ -599,7 +645,12 @@ private Dictionary<string, LibraryStub> ReadLibraries(ref Utf8JsonReader reader)

while (reader.Read() && reader.IsTokenTypeProperty())
{
string libraryName = reader.GetString()!;
string? libraryName = reader.GetString();

if (string.IsNullOrEmpty(libraryName))
{
throw new FormatException(SR.Format(SR.RequiredFieldNotSpecified, nameof(libraryName)));
}

libraries.Add(Pool(libraryName), ReadOneLibrary(ref reader));
}
Expand Down Expand Up @@ -650,10 +701,15 @@ private LibraryStub ReadOneLibrary(ref Utf8JsonReader reader)

reader.CheckEndObject();

if (string.IsNullOrEmpty(type))
{
throw new FormatException(SR.Format(SR.RequiredFieldNotSpecified, nameof(type)));
}

return new LibraryStub()
{
Hash = hash,
Type = Pool(type)!,
Type = Pool(type),
Serviceable = serviceable,
Path = path,
HashPath = hashPath,
Expand All @@ -669,9 +725,14 @@ private static List<RuntimeFallbacks> ReadRuntimes(ref Utf8JsonReader reader)

while (reader.Read() && reader.IsTokenTypeProperty())
{
string runtime = reader.GetString()!;
string? runtime = reader.GetString();
string?[] fallbacks = reader.ReadStringArray();

if (string.IsNullOrEmpty(runtime))
{
throw new FormatException(SR.Format(SR.RequiredFieldNotSpecified, nameof(runtime)));
}

runtimeFallbacks.Add(new RuntimeFallbacks(runtime, fallbacks));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema

Microsoft ResX Schema
Version 2.0

The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types

The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:

... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
Expand All @@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>

There are any number of "resheader" rows that contain simple
There are any number of "resheader" rows that contain simple
name/value pairs.

Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.

The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:

Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.

mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
Expand Down Expand Up @@ -138,4 +138,7 @@
<data name="DuplicateItem" xml:space="preserve">
<value>An item with the same key has already been added. Key: {0}</value>
</data>
</root>
<data name="RequiredFieldNotSpecified" xml:space="preserve">
<value>The required field '{0}' was not specified.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -792,5 +792,48 @@ public void IgnoresUnknownPropertiesInCompilationOptions()
context.CompilationOptions.PublicSign.Should().Be(true);
context.CompilationOptions.WarningsAsErrors.Should().Be(true);
}

[Fact]
public void FailsToReadNullLibraryType()
{
Assert.Throws<FormatException>(() => Read(
@"{
""libraries"":{
""System.Banana/1.0.0"": {
""type"": null,
""serviceable"": false,
""sha512"": ""HASH-System.Banana""
}
}
}
"));
}

[Fact]
public void FailsToReadEmptyTargetName()
{
Assert.Throws<FormatException>(() => Read(
@"{
""targets"": {
"""": {}
}
}"));
}

[Fact]
public void FailsToReadEmptyLibraryType()
{
Assert.Throws<FormatException>(() => Read(
@"{
""libraries"":{
""System.Banana/1.0.0"": {
""type"": """",
""serviceable"": false,
""sha512"": ""HASH-System.Banana""
}
}
}
"));
}
}
}