diff options
author | Sven Boemer <sbomer@gmail.com> | 2020-12-11 00:29:23 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-11 00:29:23 +0300 |
commit | 9c88abd291fafd57076ca4c26deaaf3c6c0a4c7a (patch) | |
tree | 15f103a6255a493252052227f5dd6526dcc2b81f /test/Mono.Linker.Tests.Cases.Expectations | |
parent | a86658f4602e616d71e5d6db23a30940534132e2 (diff) |
Restrict embedded XML (#1675)
* Restrict embedded XML
Embedded attributes and substitutions may only modify the containing assembly.
* Allow specifying resource name in referenced assembly
In the test infrastructure.
* Fix formatting
* PR feedback
- Allow '*' in corelib embedded attribute XML
- Reword warning messages
- Avoid calling virtual method from ctor
* Fix test on mono
Macking the core library causes problems for PEVerify:
- Removed reference to corelib creates invalid typerefs
- System types like Object aren't found
* PR feedback
* PR feedback
Diffstat (limited to 'test/Mono.Linker.Tests.Cases.Expectations')
-rw-r--r-- | test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileAfterAttribute.cs | 17 | ||||
-rw-r--r-- | test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileBeforeAttribute.cs | 32 |
2 files changed, 44 insertions, 5 deletions
diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileAfterAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileAfterAttribute.cs index 60a54a1a8..199d9b495 100644 --- a/test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileAfterAttribute.cs +++ b/test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileAfterAttribute.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace Mono.Linker.Tests.Cases.Expectations.Metadata { @@ -8,13 +8,26 @@ namespace Mono.Linker.Tests.Cases.Expectations.Metadata [AttributeUsage (AttributeTargets.Class, AllowMultiple = true)] public class SetupCompileAfterAttribute : BaseMetadataAttribute { - public SetupCompileAfterAttribute (string outputName, string[] sourceFiles, string[] references = null, string[] defines = null, string[] resources = null, string additionalArguments = null, string compilerToUse = null) + public SetupCompileAfterAttribute (string outputName, string[] sourceFiles, string[] references = null, string[] defines = null, object[] resources = null, string additionalArguments = null, string compilerToUse = null) { if (sourceFiles == null) throw new ArgumentNullException (nameof (sourceFiles)); if (string.IsNullOrEmpty (outputName)) throw new ArgumentException ("Value cannot be null or empty.", nameof (outputName)); + + if (resources != null) { + foreach (var res in resources) { + if (res is string) + continue; + if (res is string[] stringArray) { + if (stringArray.Length != 2) + throw new ArgumentException ("Entry in object[] cannot be a string[] unless it has exactly two elements, for the resource path and name", nameof (resources)); + continue; + } + throw new ArgumentException ("Each value in the object[] must be a string or a string[], either a resource path, or a path and name", nameof (resources)); + } + } } } } diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileBeforeAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileBeforeAttribute.cs index 0ede197cf..bad07736d 100644 --- a/test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileBeforeAttribute.cs +++ b/test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileBeforeAttribute.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace Mono.Linker.Tests.Cases.Expectations.Metadata { @@ -8,22 +8,48 @@ namespace Mono.Linker.Tests.Cases.Expectations.Metadata [AttributeUsage (AttributeTargets.Class, AllowMultiple = true)] public class SetupCompileBeforeAttribute : BaseMetadataAttribute { - public SetupCompileBeforeAttribute (string outputName, string[] sourceFiles, string[] references = null, string[] defines = null, string[] resources = null, string additionalArguments = null, string compilerToUse = null, bool addAsReference = true, bool removeFromLinkerInput = false) + public SetupCompileBeforeAttribute (string outputName, string[] sourceFiles, string[] references = null, string[] defines = null, object[] resources = null, string additionalArguments = null, string compilerToUse = null, bool addAsReference = true, bool removeFromLinkerInput = false) { if (sourceFiles == null) throw new ArgumentNullException (nameof (sourceFiles)); if (string.IsNullOrEmpty (outputName)) throw new ArgumentException ("Value cannot be null or empty.", nameof (outputName)); + + if (resources != null) { + foreach (var res in resources) { + if (res is string) + continue; + if (res is string[] stringArray) { + if (stringArray.Length != 2) + throw new ArgumentException ("Entry in object[] cannot be a string[] unless it has exactly two elements, for the resource path and name", nameof (resources)); + continue; + } + throw new ArgumentException ("Each value in the object[] must be a string or a string[], either a resource path, or a path and name", nameof (resources)); + } + } } - public SetupCompileBeforeAttribute (string outputName, Type[] typesToIncludeSourceFor, string[] references = null, string[] defines = null, string[] resources = null, string additionalArguments = null, string compilerToUse = null, bool addAsReference = true, bool removeFromLinkerInput = false) + public SetupCompileBeforeAttribute (string outputName, Type[] typesToIncludeSourceFor, string[] references = null, string[] defines = null, object[] resources = null, string additionalArguments = null, string compilerToUse = null, bool addAsReference = true, bool removeFromLinkerInput = false) { if (typesToIncludeSourceFor == null) throw new ArgumentNullException (nameof (typesToIncludeSourceFor)); if (string.IsNullOrEmpty (outputName)) throw new ArgumentException ("Value cannot be null or empty.", nameof (outputName)); + + if (resources != null) { + foreach (var res in resources) { + if (res is string) + continue; + if (res is string[] stringArray) { + if (stringArray.Length != 2) + throw new ArgumentException ("Entry in object[] cannot be a string[] unless it has exactly two elements, for the resource path and name", nameof (resources)); + continue; + } + throw new ArgumentException ("Each value in the object[] must be a string or a string[], either a resource path, or a path and name", nameof (resources)); + } + } } } } |