< Summary

Information
Class: IceRpc.Internal.UriExtensions
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Internal/UriExtensions.cs
Tag: 275_13775359185
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
Total methods: 1
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)
 250714    {
 250715        if (uri.Query.Length < 2)
 202716        {
 17            // no query or empty query
 202718            return (ImmutableDictionary<string, string>.Empty, null, null);
 19        }
 20        else
 48021        {
 48022            ImmutableDictionary<string, string> queryParams = ImmutableDictionary<string, string>.Empty;
 48023            string? altServer = null;
 48024            string? transport = null;
 25
 287626            foreach (string p in uri.Query.TrimStart('?').Split('&'))
 71927            {
 71928                int equalPos = p.IndexOf('=', StringComparison.Ordinal);
 71929                string name = equalPos == -1 ? p : p[..equalPos];
 71930                string value = equalPos == -1 ? "" : p[(equalPos + 1)..];
 31
 71932                if (name == "alt-server")
 11933                {
 11934                    altServer = altServer is null ? value : $"{altServer},{value}";
 11935                }
 60036                else if (name == "transport")
 21937                {
 38                    // This is the regular parsing for query parameters, even though it's not meaningful for transport.
 21939                    transport = transport is null ? value : $"{transport},{value}";
 21940                }
 41                else
 38142                {
 38143                    if (name.Length == 0)
 244                    {
 245                        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
 37950                    if (queryParams.TryGetValue(name, out string? existingValue))
 2851                    {
 2852                        queryParams = queryParams.SetItem(name, $"{existingValue},{value}");
 2853                    }
 54                    else
 35155                    {
 35156                        queryParams = queryParams.Add(name, value);
 35157                    }
 37958                }
 71759            }
 47860            return (queryParams, altServer, transport);
 61        }
 250562    }
 63}

Methods/Properties

ParseQuery(System.Uri)