Skip to content

Default XML tasks to prohibit DTDs and improve DTD error diagnostics - #14285

Merged
VolPlita merged 27 commits into
dotnet:mainfrom
VolPlita:fix-5817-tasks-prohibit-dtd-defaults
Jul 30, 2026
Merged

VolPlita merged 27 commits into
dotnet:mainfrom
VolPlita:fix-5817-tasks-prohibit-dtd-defaults

Conversation

@VolPlita

@VolPlita VolPlita commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Fixes #5817 #5810

Context

XmlPeek, XmlPoke, and XslTransformation were inconsistent around DTD handling and often produced generic errors when DTD input was blocked, making failures hard to diagnose.

Changes Made

  • Defaulted ProhibitDtd to true in XmlPeek, XmlPoke, and XslTransformation.
  • Added XmlTaskUtility to centralize XML reader settings and DTD detection helpers.
  • Added DTD-specific error paths/messages for blocked XML/XSLT inputs.
  • Kept namespace-snippet parsing behavior permissive (DtdProcessing.Ignore) for compatibility.

Testing

  • dotnet test src\Tasks.UnitTests\Microsoft.Build.Tasks.UnitTests.csproj -- --filter-method "XmlPeek"
  • dotnet test src\Tasks.UnitTests\Microsoft.Build.Tasks.UnitTests.csproj -- --filter-method "XmlPoke"
  • dotnet test src\Tasks.UnitTests\Microsoft.Build.Tasks.UnitTests.csproj -- --filter-method "XslTransformation"

Notes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR unifies DTD handling across XmlPeek, XmlPoke, and XslTransformation by introducing a shared XML settings utility, defaulting these tasks to prohibit DTDs, and improving diagnostics when DTD-bearing inputs are blocked.

Changes:

  • Default ProhibitDtd to true in XmlPeek, XmlPoke, and XslTransformation, and route XML/XSLT parsing through centralized XmlTaskUtility settings.
  • Add DTD-specific error paths/messages for load/transform failures to improve diagnosability.
  • Update/extend unit tests to cover the new DTD-prohibited diagnostics and ensure non-DTD failures still produce generic errors.

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/Tasks/XslTransformation.cs Adds ProhibitDtd defaulting to true, uses shared reader settings, and emits DTD-specific errors for XSLT load/transform.
src/Tasks/XmlTaskUtility.cs New helper for consistent XmlReaderSettings creation and DTD detection/exception classification.
src/Tasks/XmlPoke.cs Adds ProhibitDtd defaulting to true, uses shared reader settings, and emits a DTD-specific input error.
src/Tasks/XmlPeek.cs Defaults ProhibitDtd to true and adds DTD-specific input error diagnostics.
src/Tasks/Resources/Strings.resx Adds new resource entries for DTD-specific error messages for XmlPeek/XmlPoke and XslTransformation.
src/Tasks/Microsoft.Build.Tasks.csproj Includes the new XmlTaskUtility.cs in the Tasks project build.
src/Tasks.UnitTests/XslTransformation_Tests.cs Adds tests validating DTD-specific diagnostics and generic error behavior for non-DTD failures.
src/Tasks.UnitTests/XmlPoke_Tests.cs Adds tests validating DTD-specific diagnostics and generic error behavior for malformed XML.
src/Tasks.UnitTests/XmlPeek_Tests.cs Updates tests for new default behavior and adds coverage for DTD-specific diagnostics.
src/Tasks/Resources/xlf/Strings.zh-Hant.xlf Adds new trans-units for the DTD-specific messages.
src/Tasks/Resources/xlf/Strings.zh-Hans.xlf Adds new trans-units for the DTD-specific messages.
src/Tasks/Resources/xlf/Strings.tr.xlf Adds new trans-units for the DTD-specific messages.
src/Tasks/Resources/xlf/Strings.ru.xlf Adds new trans-units for the DTD-specific messages.
src/Tasks/Resources/xlf/Strings.pt-BR.xlf Adds new trans-units for the DTD-specific messages.
src/Tasks/Resources/xlf/Strings.pl.xlf Adds new trans-units for the DTD-specific messages.
src/Tasks/Resources/xlf/Strings.ko.xlf Adds new trans-units for the DTD-specific messages.
src/Tasks/Resources/xlf/Strings.ja.xlf Adds new trans-units for the DTD-specific messages.
src/Tasks/Resources/xlf/Strings.it.xlf Adds new trans-units for the DTD-specific messages.
src/Tasks/Resources/xlf/Strings.fr.xlf Adds new trans-units for the DTD-specific messages.
src/Tasks/Resources/xlf/Strings.es.xlf Adds new trans-units for the DTD-specific messages.
src/Tasks/Resources/xlf/Strings.de.xlf Adds new trans-units for the DTD-specific messages.
src/Tasks/Resources/xlf/Strings.cs.xlf Adds new trans-units for the DTD-specific messages.

Comment thread src/Tasks/XmlPeek.cs Resolved
Comment thread src/Tasks/XmlPeek.cs Resolved
Comment thread src/Tasks/XmlPoke.cs Resolved
Comment thread src/Tasks/XmlPoke.cs Resolved
Comment thread src/Tasks/XslTransformation.cs Resolved
Comment thread src/Tasks/XmlTaskUtility.cs Resolved
@VolPlita
VolPlita force-pushed the fix-5817-tasks-prohibit-dtd-defaults branch from d76e3d4 to 04cf595 Compare July 8, 2026 12:19
@VolPlita
VolPlita marked this pull request as ready for review July 8, 2026 12:58
@OvesN
OvesN requested review from AlesProkop and OvesN July 9, 2026 12:28
Comment thread src/Tasks/XmlTaskUtility.cs Resolved
Comment thread src/Tasks/XmlTaskUtility.cs Resolved
Comment thread src/Tasks/XmlTaskUtility.cs Resolved
@VolPlita
VolPlita requested a review from AlesProkop July 9, 2026 14:31
@VolPlita
VolPlita force-pushed the fix-5817-tasks-prohibit-dtd-defaults branch from 99f437d to 44b055f Compare July 9, 2026 15:19

@AlesProkop AlesProkop left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now. Just one more thing.

Comment thread src/Tasks/XslTransformation.cs Resolved
@VolPlita
VolPlita force-pushed the fix-5817-tasks-prohibit-dtd-defaults branch from 0af3674 to f159bb4 Compare July 10, 2026 08:24

@AlesProkop AlesProkop left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM now. Just resolve the failing tests.

Comment thread src/Tasks/XmlTaskUtility.cs Resolved
Comment thread src/Tasks/XslTransformation.cs Resolved
Comment thread src/Tasks/Resources/Strings.resx Resolved
Comment thread src/Tasks/XmlPeek.cs Resolved
Comment thread src/Tasks/XmlPoke.cs Resolved
Comment thread src/Tasks/XmlTaskUtility.cs Resolved
Comment thread src/Tasks/XmlTaskUtility.cs Resolved
Comment thread src/Tasks/XslTransformation.cs Resolved
This was referenced Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XmlPoke Should Use DtdProcessing.Prohibit The XslTransformation task is unable to transform XML files containing DTD

5 participants