提交 a0f06b75 编写于 作者: B Balaji Soundrarajan

Merge pull request #1399 from basoundr/fix1371DocProvProcessDTD

Make FileBasedXmlDocumentProvider not process DTDs
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using System.IO;
using Roslyn.Utilities;
using System.Threading;
namespace Microsoft.CodeAnalysis
{
......@@ -22,9 +18,9 @@ public FileBasedXmlDocumentationProvider(string filePath)
_filePath = filePath;
}
protected override XDocument GetXDocument()
protected override Stream GetSourceStream(CancellationToken cancellationToken)
{
return XDocument.Load(_filePath);
return new FileStream(_filePath, FileMode.Open, FileAccess.Read);
}
public override bool Equals(object obj)
......
......@@ -3,12 +3,10 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.IO;
using System.Threading;
using System.Xml;
using System.Xml.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis
......@@ -18,12 +16,21 @@ internal abstract class XmlDocumentationProvider : DocumentationProvider
private NonReentrantLock _gate = new NonReentrantLock();
private Dictionary<string, string> _docComments;
protected abstract Stream GetSourceStream(CancellationToken cancellationToken);
public static XmlDocumentationProvider Create(byte[] xmlDocCommentBytes)
{
return new ContentBasedXmlDocumentationProvider(xmlDocCommentBytes);
}
protected abstract XDocument GetXDocument();
private XDocument GetXDocument(CancellationToken cancellationToken)
{
using (var stream = GetSourceStream(cancellationToken))
using (var xmlReader = XmlReader.Create(stream, s_xmlSettings))
{
return XDocument.Load(xmlReader);
}
}
protected override string GetDocumentationForSymbol(string documentationMemberID, CultureInfo preferredCulture, CancellationToken cancellationToken = default(CancellationToken))
{
......@@ -35,12 +42,12 @@ protected override string GetDocumentationForSymbol(string documentationMemberID
{
_docComments = new Dictionary<string, string>();
XDocument doc = this.GetXDocument();
XDocument doc = this.GetXDocument(cancellationToken);
foreach (var e in doc.Descendants("member"))
{
if (e.Attribute("name") != null)
{
_docComments[e.Attribute("name").Value] = e.Value;
_docComments[e.Attribute("name").Value] = string.Concat(e.Nodes());
}
}
}
......@@ -70,13 +77,9 @@ public ContentBasedXmlDocumentationProvider(byte[] xmlDocCommentBytes)
_xmlDocCommentBytes = xmlDocCommentBytes;
}
protected override XDocument GetXDocument()
protected override Stream GetSourceStream(CancellationToken cancellationToken)
{
using (var stream = SerializableBytes.CreateReadableStream(_xmlDocCommentBytes, CancellationToken.None))
using (var xmlReader = XmlReader.Create(stream, s_xmlSettings))
{
return XDocument.Load(xmlReader);
}
return SerializableBytes.CreateReadableStream(_xmlDocCommentBytes, cancellationToken);
}
public override bool Equals(object obj)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册