C# 클래스 Microsoft.CodeAnalysis.Sarif.UriHelper

파일 보기 프로젝트 열기: Microsoft/sarif-sdk 1 사용 예제들

공개 메소드들

메소드 설명
MakeValidUri ( string path ) : string

Create a syntactically valid URI from a path that might be absolute or relative, and that might require percent-encoding.

In general, path might be: 1. Possible to interpret as an absolute path / absolute URI 2. Possible to interpret as a relative path / relative URI 3. Neither We must create a valid URI to persist in the SARIF log. We proceed as follows: 1. Try to create an absolute System.Uri. If that succeeds, take its AbsoluteUri, which (unlike Uri.ToString()) will be properly percent-encoded. 2. Try to create a relative System.Uri. If that succeeds, we want to write it out, but since this is a relative URI, we can't access its AbsoluteUri or AbsolutePath property -- and again, Uri.ToString() does not perform percent encoding. We use this workaround: a. Combine the relative path with an arbitrary scheme and host to form an absolute URI. b. Extract the AbsolutePath property, which will be percent encoded. 3. If all else fails, we have a string that we can't convert to a System.Uri, so just percent encode the whole thing. This should be extremely rare in practice. Thanks and a tip o' the hat to @nguerrera for this code (and for the comment).

비공개 메소드들

메소드 설명
GetLeadingDotSegments ( string path ) : string

메소드 상세

MakeValidUri() 공개 정적인 메소드

Create a syntactically valid URI from a path that might be absolute or relative, and that might require percent-encoding.
In general, path might be: 1. Possible to interpret as an absolute path / absolute URI 2. Possible to interpret as a relative path / relative URI 3. Neither We must create a valid URI to persist in the SARIF log. We proceed as follows: 1. Try to create an absolute System.Uri. If that succeeds, take its AbsoluteUri, which (unlike Uri.ToString()) will be properly percent-encoded. 2. Try to create a relative System.Uri. If that succeeds, we want to write it out, but since this is a relative URI, we can't access its AbsoluteUri or AbsolutePath property -- and again, Uri.ToString() does not perform percent encoding. We use this workaround: a. Combine the relative path with an arbitrary scheme and host to form an absolute URI. b. Extract the AbsolutePath property, which will be percent encoded. 3. If all else fails, we have a string that we can't convert to a System.Uri, so just percent encode the whole thing. This should be extremely rare in practice. Thanks and a tip o' the hat to @nguerrera for this code (and for the comment).
public static MakeValidUri ( string path ) : string
path string /// The path to be transformed into a syntactically valid URI. ///
리턴 string