< Summary

Information
Class: IceRpc.Internal.UriExtensions
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Internal/UriExtensions.cs
Tag: 592_20856082467
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)
 134914    {
 134915        if (uri.Query.Length < 2)
 108316        {
 17            // no query or empty query
 108318            return (ImmutableDictionary<string, string>.Empty, null, null);
 19        }
 20        else
 26621        {
 26622            ImmutableDictionary<string, string> queryParams = ImmutableDictionary<string, string>.Empty;
 26623            string? altServer = null;
 26624            string? transport = null;
 25
 160926            foreach (string p in uri.Query.TrimStart('?').Split('&'))
 40627            {
 40628                int equalPos = p.IndexOf('=', StringComparison.Ordinal);
 40629                string name = equalPos == -1 ? p : p[..equalPos];
 40630                string value = equalPos == -1 ? "" : p[(equalPos + 1)..];
 31
 40632                if (name == "alt-server")
 6133                {
 6134                    altServer = altServer is null ? value : $"{altServer},{value}";
 6135                }
 34536                else if (name == "transport")
 12837                {
 38                    // This is the regular parsing for query parameters, even though it's not meaningful for transport.
 12839                    transport = transport is null ? value : $"{transport},{value}";
 12840                }
 41                else
 21742                {
 21743                    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
 21650                    if (queryParams.TryGetValue(name, out string? existingValue))
 1451                    {
 1452                        queryParams = queryParams.SetItem(name, $"{existingValue},{value}");
 1453                    }
 54                    else
 20255                    {
 20256                        queryParams = queryParams.Add(name, value);
 20257                    }
 21658                }
 40559            }
 26560            return (queryParams, altServer, transport);
 61        }
 134862    }
 63}

Methods/Properties

ParseQuery(System.Uri)