< Summary

Information
Class: IceRpc.Internal.UriExtensions
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Internal/UriExtensions.cs
Tag: 1856_27024993493
Line coverage
100%
Covered lines: 36
Uncovered lines: 0
Coverable lines: 36
Total lines: 63
Line coverage: 100%
Branch coverage
95%
Covered branches: 19
Total branches: 20
Branch coverage: 95%
Method coverage
100%
Covered methods: 1
Fully covered methods: 1
Total methods: 1
Method coverage: 100%
Full method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ParseQuery(...)95%2020100%

File(s)

/home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Internal/UriExtensions.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3using System.Collections.Immutable;
 4
 5namespace IceRpc.Internal;
 6
 7/// <summary>Extension methods for <see cref="Uri" />.</summary>
 8internal static class UriExtensions
 9{
 10    /// <summary>Parses the query portion of a URI into a dictionary of name/value. The value of the alt-server
 11    /// and transport parameters, if set, are returned separately.</summary>
 12    internal static (ImmutableDictionary<string, string> QueryParams, string? AltServerValue, string? TransportValue) Pa
 13        this Uri uri)
 137514    {
 137515        if (uri.Query.Length < 2)
 112716        {
 17            // no query or empty query
 112718            return (ImmutableDictionary<string, string>.Empty, null, null);
 19        }
 20        else
 24821        {
 24822            ImmutableDictionary<string, string> queryParams = ImmutableDictionary<string, string>.Empty;
 24823            string? altServer = null;
 24824            string? transport = null;
 25
 149926            foreach (string p in uri.Query.TrimStart('?').Split('&'))
 37827            {
 37828                int equalPos = p.IndexOf('=', StringComparison.Ordinal);
 37829                string name = equalPos == -1 ? p : p[..equalPos];
 37830                string value = equalPos == -1 ? "" : p[(equalPos + 1)..];
 31
 37832                if (name == "alt-server")
 6033                {
 6034                    altServer = altServer is null ? value : $"{altServer},{value}";
 6035                }
 31836                else if (name == "transport")
 11237                {
 38                    // This is the regular parsing for query parameters, even though it's not meaningful for transport.
 11239                    transport = transport is null ? value : $"{transport},{value}";
 11240                }
 41                else
 20642                {
 20643                    if (name.Length == 0)
 144                    {
 145                        throw new FormatException($"Invalid empty query parameter name in URI '{uri.OriginalString}'.");
 46                    }
 47
 48                    // we assume the C# URI parser validates the name and value sufficiently
 49
 20550                    if (queryParams.TryGetValue(name, out string? existingValue))
 1451                    {
 1452                        queryParams = queryParams.SetItem(name, $"{existingValue},{value}");
 1453                    }
 54                    else
 19155                    {
 19156                        queryParams = queryParams.Add(name, value);
 19157                    }
 20558                }
 37759            }
 24760            return (queryParams, altServer, transport);
 61        }
 137462    }
 63}

Methods/Properties

ParseQuery(System.Uri)