< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 52
Coverable lines: 52
Total lines: 145
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 22
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%110%
MapGenericParserOptions(...)0%22220%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Private.Uri/src/System/GenericUriParser.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4namespace System
 5{
 6
 7    //
 8    // This enum specifies the public options used to customize a hierarchical built-in parser.
 9    //
 10    [Flags]
 11    public enum GenericUriParserOptions
 12    {
 13        // A hierarchical URI, allows a userinfo, non empty Inet-based authority, path, query and fragment
 14        // The URI path gets aggressively compressed means dots, slashes and backslashes are unescaped,
 15        // backslashesare converted, and then it compresses the path. It also removes trailing dots,
 16        // empty segments and dots-only segments
 17        Default                         = 0x0,
 18
 19        // Allows a free style authority that would terminate with '/'
 20        GenericAuthority           = 0x1,
 21
 22        // Allows an empty authority foo:///
 23        AllowEmptyAuthority        = 0x2,
 24
 25        // Disables a user info component, it implied in the case of GenericAuthority flag
 26        NoUserInfo                 = 0x4,
 27
 28        // Disables a port component, it is implied in the case of GenericAuthority flag
 29        NoPort                     = 0x8,
 30
 31        // Disables a query. A ? char is considered as part of the path and is escaped
 32        NoQuery                    = 0x10,
 33
 34        // Disables a fragment. A # char is considered as part of the path or query and is escaped
 35        NoFragment                 = 0x20,
 36
 37        // if false then converta \ to /, otherwise does this conversion for the Path component.
 38        DontConvertPathBackslashes = 0x40,
 39
 40        // if false, then a/./b or a/.../b becomes a/b and /a/../b becomes /b
 41        DontCompressPath           = 0x80,
 42
 43        // if false  then a/%2e./b  becomes a/../b and then usually compressed
 44        DontUnescapePathDotsAndSlashes= 0x100,
 45
 46        // IDN hosts supported. if true then unicode hostname is converted to IDN host
 47        //  and vice versa
 48        Idn = 0x200,
 49
 50        //  Iri strict parsing flag. Makes sense for Unicode. If true then string is
 51        //  normalized, bidi control characters are removed, unicode char limits are checked
 52        IriParsing = 0x400
 53    }
 54
 55    public class GenericUriParser : UriParser
 56    {
 057        public GenericUriParser(GenericUriParserOptions options) : base(MapGenericParserOptions(options))
 058        {
 059        }
 60
 61        private static UriSyntaxFlags MapGenericParserOptions(GenericUriParserOptions options)
 062        {
 63            //
 64            // Here we map public flags to internal ones
 65            // Note an instacne of this parser is always a "simple parser" since the class is sealed.
 66            //
 067            UriSyntaxFlags flags = DefaultGenericUriParserFlags;
 68
 069            if ((options & GenericUriParserOptions.GenericAuthority) != 0)
 070            {
 71                // Disable some options that are not compatible with generic authority
 072                flags &= ~(UriSyntaxFlags.MayHaveUserInfo | UriSyntaxFlags.MayHavePort | UriSyntaxFlags.AllowUncHost | U
 073                flags |= UriSyntaxFlags.AllowAnyOtherHost;
 074            }
 75
 076            if ((options & GenericUriParserOptions.AllowEmptyAuthority) != 0)
 077            {
 078                flags |= UriSyntaxFlags.AllowEmptyHost;
 079            }
 80
 081            if ((options & GenericUriParserOptions.NoUserInfo) != 0)
 082            {
 083                flags &= ~UriSyntaxFlags.MayHaveUserInfo;
 084            }
 85
 086            if ((options & GenericUriParserOptions.NoPort) != 0)
 087            {
 088                flags &= ~UriSyntaxFlags.MayHavePort;
 089            }
 90
 091            if ((options & GenericUriParserOptions.NoQuery) != 0)
 092            {
 093                flags &= ~UriSyntaxFlags.MayHaveQuery;
 094            }
 95
 096            if ((options & GenericUriParserOptions.NoFragment) != 0)
 097            {
 098                flags &= ~UriSyntaxFlags.MayHaveFragment;
 099            }
 100
 0101            if ((options & GenericUriParserOptions.DontConvertPathBackslashes) != 0)
 0102            {
 0103                flags &= ~UriSyntaxFlags.ConvertPathSlashes;
 0104            }
 105
 0106            if ((options & GenericUriParserOptions.DontCompressPath) != 0)
 0107            {
 0108                flags &= ~(UriSyntaxFlags.CompressPath | UriSyntaxFlags.CanonicalizeAsFilePath);
 0109            }
 110
 0111            if ((options & GenericUriParserOptions.DontUnescapePathDotsAndSlashes) != 0)
 0112            {
 0113                flags &= ~UriSyntaxFlags.UnEscapeDotsAndSlashes;
 0114            }
 115
 0116            if ((options & GenericUriParserOptions.Idn) != 0)
 0117            {
 0118                flags |= UriSyntaxFlags.AllowIdn;
 0119            }
 120
 0121            if ((options & GenericUriParserOptions.IriParsing) != 0)
 0122            {
 0123                flags |= UriSyntaxFlags.AllowIriParsing;
 0124            }
 125
 0126            return flags;
 0127        }
 128
 129        private const UriSyntaxFlags DefaultGenericUriParserFlags =
 130                                                                    UriSyntaxFlags.MustHaveAuthority |
 131                                                                    UriSyntaxFlags.MayHaveUserInfo |
 132                                                                    UriSyntaxFlags.MayHavePort |
 133                                                                    UriSyntaxFlags.MayHavePath |
 134                                                                    UriSyntaxFlags.MayHaveQuery |
 135                                                                    UriSyntaxFlags.MayHaveFragment |
 136                                                                    UriSyntaxFlags.AllowUncHost |
 137                                                                    UriSyntaxFlags.AllowAnInternetHost |
 138                                                                    UriSyntaxFlags.PathIsRooted |
 139                                                                    UriSyntaxFlags.ConvertPathSlashes |
 140                                                                    UriSyntaxFlags.CompressPath |
 141                                                                    UriSyntaxFlags.CanonicalizeAsFilePath |
 142                                                                    UriSyntaxFlags.UnEscapeDotsAndSlashes;
 143    }
 144}
 145