< Summary

Information
Class: IceRpc.Internal.UriExtensions
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Internal/UriExtensions.cs
Tag: 1321_24790053727
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)
 133214    {
 133215        if (uri.Query.Length < 2)
 109416        {
 17            // no query or empty query
 109418            return (ImmutableDictionary<string, string>.Empty, null, null);
 19        }
 20        else
 23821        {
 23822            ImmutableDictionary<string, string> queryParams = ImmutableDictionary<string, string>.Empty;
 23823            string? altServer = null;
 23824            string? transport = null;
 25
 144926            foreach (string p in uri.Query.TrimStart('?').Split('&'))
 36827            {
 36828                int equalPos = p.IndexOf('=', StringComparison.Ordinal);
 36829                string name = equalPos == -1 ? p : p[..equalPos];
 36830                string value = equalPos == -1 ? "" : p[(equalPos + 1)..];
 31
 36832                if (name == "alt-server")
 6033                {
 6034                    altServer = altServer is null ? value : $"{altServer},{value}";
 6035                }
 30836                else if (name == "transport")
 10837                {
 38                    // This is the regular parsing for query parameters, even though it's not meaningful for transport.
 10839                    transport = transport is null ? value : $"{transport},{value}";
 10840                }
 41                else
 20042                {
 20043                    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
 19950                    if (queryParams.TryGetValue(name, out string? existingValue))
 1451                    {
 1452                        queryParams = queryParams.SetItem(name, $"{existingValue},{value}");
 1453                    }
 54                    else
 18555                    {
 18556                        queryParams = queryParams.Add(name, value);
 18557                    }
 19958                }
 36759            }
 23760            return (queryParams, altServer, transport);
 61        }
 133162    }
 63}

Methods/Properties

ParseQuery(System.Uri)