-
Notifications
You must be signed in to change notification settings - Fork 5k
Obsolete XmlSecureResolver #73676
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
Obsolete XmlSecureResolver #73676
Changes from all commits
e618e45
3210fb3
5ad0e26
6ed1536
2657d65
286657d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Net; | ||
using System.Threading.Tasks; | ||
|
||
namespace System.Xml | ||
{ | ||
public abstract partial class XmlResolver | ||
{ | ||
/// <summary> | ||
/// Gets an XML resolver which forbids entity resolution. | ||
/// </summary> | ||
/// <value>An XML resolver which forbids entity resolution.</value> | ||
/// <remarks> | ||
/// Calling <see cref="GetEntity"/> or <see cref="GetEntityAsync"/> on the | ||
/// <see cref="XmlResolver"/> instance returned by this property is forbidden | ||
/// and will result in <see cref="XmlException"/> being thrown. | ||
/// | ||
/// Use <see cref="ThrowingResolver"/> when external entity resolution must be | ||
/// prohibited, even when DTD processing is otherwise enabled. | ||
/// </remarks> | ||
public static XmlResolver ThrowingResolver => XmlThrowingResolver.s_singleton; | ||
|
||
// An XmlResolver that forbids all external entity resolution. | ||
private sealed class XmlThrowingResolver : XmlResolver | ||
{ | ||
internal static readonly XmlThrowingResolver s_singleton = new(); | ||
|
||
// Private constructor ensures existing only one instance of XmlThrowingResolver | ||
private XmlThrowingResolver() { } | ||
|
||
public override ICredentials Credentials | ||
{ | ||
set { /* Do nothing */ } | ||
} | ||
|
||
public override object GetEntity(Uri absoluteUri, string? role, Type? ofObjectToReturn) | ||
{ | ||
throw new XmlException(SR.Format(SR.Xml_NullResolver, absoluteUri)); | ||
} | ||
|
||
public override Task<object> GetEntityAsync(Uri absoluteUri, string? role, Type? ofObjectToReturn) | ||
{ | ||
throw new XmlException(SR.Format(SR.Xml_NullResolver, absoluteUri)); | ||
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. Do we care about inside vs outside the task here? It looks like other implementations are throwing XmlException "outside" the task, so I guess this isn't entirely wrong. 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. It's one of those weird edge cases that doesn't cleanly fit into any bucket. If I squint I can kinda claim that it's a usage error, since the caller shouldn't be invoking it in the first place. But ultimately I followed the pattern that the previous implementation threw the exception synchronously rather than wrapped within a task. |
||
} | ||
} | ||
} | ||
} |
This file was deleted.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.