-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add switch: Do not resolve URLs by defaults for XML #84169
Changes from all commits
dc483c8
0dc5170
5c49b26
7dcbdbd
3792282
608da91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,18 +2,19 @@ | |
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Runtime.CompilerServices; | ||
using SwitchesHelpers = System.LocalAppContextSwitches; | ||
|
||
namespace System | ||
namespace System.Xml | ||
{ | ||
internal static partial class LocalAppContextSwitches | ||
internal static class LocalAppContextSwitches | ||
{ | ||
private static int s_dontThrowOnInvalidSurrogatePairs; | ||
public static bool DontThrowOnInvalidSurrogatePairs | ||
{ | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
get | ||
{ | ||
return GetCachedSwitchValue("Switch.System.Xml.DontThrowOnInvalidSurrogatePairs", ref s_dontThrowOnInvalidSurrogatePairs); | ||
return SwitchesHelpers.GetCachedSwitchValue("Switch.System.Xml.DontThrowOnInvalidSurrogatePairs", ref s_dontThrowOnInvalidSurrogatePairs); | ||
} | ||
} | ||
|
||
|
@@ -23,7 +24,7 @@ public static bool IgnoreEmptyKeySequences | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
get | ||
{ | ||
return GetCachedSwitchValue("Switch.System.Xml.IgnoreEmptyKeySequencess", ref s_ignoreEmptyKeySequences); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NOTE: there used to be a typo in the switch name here, I have fixed it here according to how it's documented: |
||
return SwitchesHelpers.GetCachedSwitchValue("Switch.System.Xml.IgnoreEmptyKeySequences", ref s_ignoreEmptyKeySequences); | ||
} | ||
} | ||
|
||
|
@@ -33,7 +34,7 @@ public static bool IgnoreKindInUtcTimeSerialization | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
get | ||
{ | ||
return GetCachedSwitchValue("Switch.System.Xml.IgnoreKindInUtcTimeSerialization", ref s_ignoreKindInUtcTimeSerialization); | ||
return SwitchesHelpers.GetCachedSwitchValue("Switch.System.Xml.IgnoreKindInUtcTimeSerialization", ref s_ignoreKindInUtcTimeSerialization); | ||
} | ||
} | ||
|
||
|
@@ -43,7 +44,7 @@ public static bool LimitXPathComplexity | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
get | ||
{ | ||
return GetCachedSwitchValue("Switch.System.Xml.LimitXPathComplexity", ref s_limitXPathComplexity); | ||
krwq marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return SwitchesHelpers.GetCachedSwitchValue("Switch.System.Xml.LimitXPathComplexity", ref s_limitXPathComplexity); | ||
} | ||
} | ||
|
||
|
@@ -53,7 +54,17 @@ public static bool AllowDefaultResolver | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
get | ||
{ | ||
return GetCachedSwitchValue("Switch.System.Xml.AllowDefaultResolver", ref s_allowDefaultResolver); | ||
return SwitchesHelpers.GetCachedSwitchValue("Switch.System.Xml.AllowDefaultResolver", ref s_allowDefaultResolver); | ||
} | ||
} | ||
|
||
private static int s_isNetworkingEnabledByDefault; | ||
public static bool IsNetworkingEnabledByDefault | ||
{ | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
get | ||
{ | ||
return SwitchesHelpers.GetCachedSwitchValue("System.Xml.XmlResolver.IsNetworkingEnabledByDefault", ref s_isNetworkingEnabledByDefault); | ||
} | ||
} | ||
} | ||
|
This file was deleted.
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this really need to be in a new file? Why can't it just be in the main There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I followed convention for the ThrowingResolver |
||
{ | ||
/// <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. | ||
jkotas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: this method is moved from |
||
} | ||
} | ||
|
||
throw new XmlException(SR.Xml_UnsupportedClass, string.Empty); | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried reverting this but VS keeps on changing this back