Skip to content

Commit 40e90f3

Browse files
Copilotjeffhandleytannergooding
authored
Obsolete XsltSettings.EnableScript with SYSLIB0062 (#117701)
* Initial plan * Add SYSLIB0062 obsoletion for XsltSettings.EnableScript Co-authored-by: jeffhandley <[email protected]> * Update SYSLIB0062 message to be more concise and fix test warnings Co-authored-by: jeffhandley <[email protected]> * Remove SYSLIB0062 from blanket NoWarn list for partial facade assemblies Co-authored-by: tannergooding <[email protected]> * Move pragma warning restore to encompass entire obsolete API usage blocks Co-authored-by: jeffhandley <[email protected]> * Obsolete Scripts field and move pragma warnings to encompass entire obsolete API usage blocks Co-authored-by: jeffhandley <[email protected]> * Use Obsoletions constants --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: jeffhandley <[email protected]> Co-authored-by: tannergooding <[email protected]> Co-authored-by: Jeff Handley <[email protected]>
1 parent 0b2f272 commit 40e90f3

File tree

10 files changed

+21
-0
lines changed

10 files changed

+21
-0
lines changed

docs/project/list-of-diagnostics.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ The PR that reveals the implementation of the `<IncludeInternalObsoleteAttribute
116116
| __`SYSLIB0059`__ | SystemEvents.EventsThreadShutdown callbacks are not run before the process exits. Use AppDomain.ProcessExit instead. |
117117
| __`SYSLIB0060`__ | The constructors on Rfc2898DeriveBytes are obsolete. Use the static Pbkdf2 method instead. |
118118
| __`SYSLIB0061`__ | The Queryable MinBy and MaxBy taking an IComparer\<TSource\> are obsolete. Use the new ones that take an IComparer\<TKey\>. |
119+
| __`SYSLIB0062`__ | XSLT Script blocks are not supported. |
119120

120121
## Analyzer Warnings
121122

src/libraries/Common/src/System/Obsoletions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ internal static class Obsoletions
195195
internal const string QueryableMinByMaxByTSourceObsoleteMessage = "The Queryable MinBy and MaxBy taking an IComparer<TSource> are obsolete. Use the new ones that take an IComparer<TKey>.";
196196
internal const string QueryableMinByMaxByTSourceObsoleteDiagId = "SYSLIB0061";
197197

198+
internal const string XsltSettingsEnableScriptMessage = "XSLT Script blocks are not supported.";
199+
internal const string XsltSettingsEnableScriptDiagId = "SYSLIB0062";
200+
198201
// When adding a new diagnostic ID, add it to the table in docs\project\list-of-diagnostics.md as well.
199202
// Keep new const identifiers above this comment.
200203
}

src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/Compiler.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ internal sealed class Compiler
4242
public int CurrentPrecedence; // Decreases by 1 with each import
4343
public XslNode? StartApplyTemplates;
4444
public RootLevel? Root;
45+
[Obsolete(Obsoletions.XsltSettingsEnableScriptMessage, DiagnosticId = Obsoletions.XsltSettingsEnableScriptDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
4546
public Scripts Scripts;
4647
public Output Output = new Output();
4748
public List<VarPar> ExternalPars = new List<VarPar>();
@@ -67,7 +68,9 @@ public Compiler(XsltSettings settings, bool debug, string? scriptAssemblyPath)
6768
ScriptAssemblyPath = scriptAssemblyPath;
6869

6970
CompilerErrorColl = new CompilerErrorCollection();
71+
#pragma warning disable SYSLIB0062 // Scripts field is obsolete
7072
Scripts = new Scripts(this);
73+
#pragma warning restore SYSLIB0062
7174
}
7275

7376
public CompilerErrorCollection Compile(object stylesheet, XmlResolver? xmlResolver, XmlResolver? origResolver, out QilExpression qil)

src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/QilGenerator.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,9 @@ private QilExpression Compile(Compiler compiler)
195195
}
196196

197197
// Create list of all early bound objects
198+
#pragma warning disable SYSLIB0062 // Scripts field is obsolete
198199
Scripts.TrimSafeDictionary scriptClasses = compiler.Scripts.ScriptClasses;
200+
#pragma warning restore SYSLIB0062
199201
List<EarlyBoundInfo> ebTypes = new List<EarlyBoundInfo>(scriptClasses.Count);
200202
foreach (string key in scriptClasses.Keys)
201203
{
@@ -261,10 +263,12 @@ private void CompileInitializationCode()
261263
}
262264

263265
// Register all script namespaces
266+
#pragma warning disable SYSLIB0062 // Scripts field is obsolete
264267
foreach (string scriptNs in _compiler.Scripts.ScriptClasses.Keys)
265268
{
266269
init = _f.Add(init, _f.InvokeCheckScriptNamespace(scriptNs));
267270
}
271+
#pragma warning restore SYSLIB0062
268272

269273
if (init.NodeType == QilNodeType.Add)
270274
{

src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/QilGeneratorEnv.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ QilNode IXPathEnvironment.ResolveFunction(string prefix, string name, IList<QilN
213213
for (int i = 0; i < args.Count; i++)
214214
args[i] = _f.SafeDocOrderDistinct(args[i]);
215215

216+
#pragma warning disable SYSLIB0062 // XsltSettings.EnableScript is obsolete
216217
if (_compiler.Settings.EnableScript)
217218
{
218219
XmlExtensionFunction? scrFunc = _compiler.Scripts.ResolveFunction(name, ns, args.Count, (IErrorHelper)this);
@@ -229,6 +230,7 @@ QilNode IXPathEnvironment.ResolveFunction(string prefix, string name, IList<QilN
229230
return _f.Error(_lastScope!.SourceLine, SR.Xslt_ScriptsProhibited);
230231
}
231232
}
233+
#pragma warning restore SYSLIB0062
232234

233235
return _f.XsltInvokeLateBound(_f.QName(name, ns, prefix), args);
234236
}

src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/XslAstAnalyzer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,7 @@ public XslFlags Function(string prefix, string name, IList<XslFlags> args)
11341134
{
11351135
// Unknown function. Can be script function or extension function
11361136
funcFlags = XslFlags.AnyType;
1137+
#pragma warning disable SYSLIB0062 // XsltSettings.EnableScript is obsolete
11371138
if (_compiler.Settings.EnableScript && ns != null)
11381139
{
11391140
XmlExtensionFunction? scrFunc = _compiler.Scripts.ResolveFunction(name, ns, args.Count, default(NullErrorHelper));
@@ -1175,6 +1176,7 @@ public XslFlags Function(string prefix, string name, IList<XslFlags> args)
11751176
}
11761177
}
11771178
funcFlags |= XslFlags.SideEffects;
1179+
#pragma warning restore SYSLIB0062
11781180
}
11791181
}
11801182

src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/XsltLoader.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,12 +1309,14 @@ private void LoadMsScript(NsDecl? stylesheetNsList)
13091309
scriptNs ??= _compiler.CreatePhantomNamespace();
13101310
ParseStringAttribute(1, "language");
13111311

1312+
#pragma warning disable SYSLIB0062 // XsltSettings.EnableScript is obsolete
13121313
if (!_compiler.Settings.EnableScript)
13131314
{
13141315
_compiler.Scripts.ScriptClasses[scriptNs] = null;
13151316
_input.SkipNode();
13161317
return;
13171318
}
1319+
#pragma warning restore SYSLIB0062
13181320

13191321
throw new PlatformNotSupportedException(SR.CompilingScriptsNotSupported); // Not adding any scripts as script compilation is not available
13201322
}

src/libraries/System.Private.Xml/src/System/Xml/Xslt/XsltSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public bool EnableDocumentFunction
3939
set { _enableDocumentFunction = value; }
4040
}
4141

42+
[Obsolete(Obsoletions.XsltSettingsEnableScriptMessage, DiagnosticId = Obsoletions.XsltSettingsEnableScriptDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
4243
public bool EnableScript
4344
{
4445
get { return _enableScript; }

src/libraries/System.Private.Xml/tests/Xslt/XslCompiledTransformApi/XsltSettings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,9 @@ public void XsltSettings1_2(object param0, object param1, object param2, object
208208
_xsl.Load(_xslFile, xs, new XmlUrlResolver());
209209

210210
xs.EnableDocumentFunction = (bool)param5;
211+
#pragma warning disable SYSLIB0062 // XsltSettings.EnableScript is obsolete
211212
xs.EnableScript = (bool)param6;
213+
#pragma warning restore SYSLIB0062
212214
_xsl.Load(_xslFile, xs, new XmlUrlResolver());
213215

214216
try

src/libraries/System.Xml.ReaderWriter/ref/System.Xml.ReaderWriter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2942,6 +2942,7 @@ public XsltSettings() { }
29422942
public XsltSettings(bool enableDocumentFunction, bool enableScript) { }
29432943
public static System.Xml.Xsl.XsltSettings Default { get { throw null; } }
29442944
public bool EnableDocumentFunction { get { throw null; } set { } }
2945+
[System.ObsoleteAttribute("XSLT Script blocks are not supported.", DiagnosticId = "SYSLIB0062", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
29452946
public bool EnableScript { get { throw null; } set { } }
29462947
public static System.Xml.Xsl.XsltSettings TrustedXslt { get { throw null; } }
29472948
}

0 commit comments

Comments
 (0)