-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add switch: Do not resolve URLs by defaults for XML (#84169)
* Add switch: Do not resolve URLs by defaults for XML * feedback, test * rename switch per API review * Apply missed feedback, fix test failure * Fix typo in IgnoreEmptyKeySequences Co-authored-by: David Cantú <[email protected]> * Update src/libraries/System.Private.Xml/tests/TrimmingTests/XmlUrlResolverDefaults.IsNetworkingEnabledByDefault.cs Co-authored-by: David Cantú <[email protected]> --------- Co-authored-by: David Cantú <[email protected]>
- Loading branch information
Showing
22 changed files
with
258 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/libraries/System.Private.Xml/src/ILLink/ILLink.Substitutions.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<linker> | ||
<assembly fullname="System.Private.Xml"> | ||
<type fullname="System.Xml.LocalAppContextSwitches"> | ||
<method signature="System.Boolean get_IsNetworkingEnabledByDefault()" body="stub" value="false" | ||
feature="System.Xml.XmlResolver.IsNetworkingEnabledByDefault" featurevalue="false" /> | ||
</type> | ||
</assembly> | ||
</linker> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 0 additions & 53 deletions
53
src/libraries/System.Private.Xml/src/System/Xml/XmlDownloadManagerAsync.cs
This file was deleted.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
src/libraries/System.Private.Xml/src/System/Xml/XmlResolver.FileSystemResolver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.IO; | ||
using System.Threading.Tasks; | ||
|
||
namespace System.Xml | ||
{ | ||
public abstract partial class XmlResolver | ||
{ | ||
/// <summary> | ||
/// Gets an XML resolver which resolves only file system URIs. | ||
/// </summary> | ||
/// <value>An XML resolver which resolves only file system URIs.</value> | ||
/// <remarks> | ||
/// Calling <see cref="GetEntity"/> or <see cref="GetEntityAsync"/> on the | ||
/// <see cref="XmlResolver"/> instance returned by this property will resolve only URIs which scheme is file. | ||
/// </remarks> | ||
public static XmlResolver FileSystemResolver => XmlFileSystemResolver.s_singleton; | ||
|
||
// An XML resolver that resolves only file system URIs. | ||
private sealed class XmlFileSystemResolver : XmlResolver | ||
{ | ||
internal static readonly XmlFileSystemResolver s_singleton = new(); | ||
|
||
// Private constructor ensures existing only one instance of XmlFileSystemResolver | ||
private XmlFileSystemResolver() { } | ||
|
||
public override object? GetEntity(Uri absoluteUri, string? role, Type? ofObjectToReturn) | ||
{ | ||
if ((ofObjectToReturn is null || ofObjectToReturn == typeof(Stream) || ofObjectToReturn == typeof(object)) | ||
&& absoluteUri.Scheme == "file") | ||
{ | ||
return new FileStream(absoluteUri.LocalPath, FileMode.Open, FileAccess.Read, FileShare.Read, 1); | ||
} | ||
|
||
throw new XmlException(SR.Xml_UnsupportedClass, string.Empty); | ||
} | ||
|
||
public override Task<object> GetEntityAsync(Uri absoluteUri, string? role, Type? ofObjectToReturn) | ||
{ | ||
if (ofObjectToReturn == null || ofObjectToReturn == typeof(Stream) || ofObjectToReturn == typeof(object)) | ||
{ | ||
if (absoluteUri.Scheme == "file") | ||
{ | ||
return Task.FromResult<object>(new FileStream(absoluteUri.LocalPath, FileMode.Open, FileAccess.Read, FileShare.Read, 1, useAsync: true)); | ||
} | ||
} | ||
|
||
throw new XmlException(SR.Xml_UnsupportedClass, string.Empty); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.