< Summary

Information
Class: IceRpc.Internal.UriExtensions
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Internal/UriExtensions.cs
Tag: 1986_28452893481
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)
 139114    {
 139115        if (uri.Query.Length < 2)
 114116        {
 17            // no query or empty query
 114118            return (ImmutableDictionary<string, string>.Empty, null, null);
 19        }
 20        else
 25021        {
 25022            ImmutableDictionary<string, string> queryParams = ImmutableDictionary<string, string>.Empty;
 25023            string? altServer = null;
 25024            string? transport = null;
 25
 150926            foreach (string p in uri.Query.TrimStart('?').Split('&'))
 38027            {
 38028                int equalPos = p.IndexOf('=', StringComparison.Ordinal);
 38029                string name = equalPos == -1 ? p : p[..equalPos];
 38030                string value = equalPos == -1 ? "" : p[(equalPos + 1)..];
 31
 38032                if (name == "alt-server")
 6033                {
 6034                    altServer = altServer is null ? value : $"{altServer},{value}";
 6035                }
 32036                else if (name == "transport")
 11337                {
 38                    // This is the regular parsing for query parameters, even though it's not meaningful for transport.
 11339                    transport = transport is null ? value : $"{transport},{value}";
 11340                }
 41                else
 20742                {
 20743                    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
 20650                    if (queryParams.TryGetValue(name, out string? existingValue))
 1451                    {
 1452                        queryParams = queryParams.SetItem(name, $"{existingValue},{value}");
 1453                    }
 54                    else
 19255                    {
 19256                        queryParams = queryParams.Add(name, value);
 19257                    }
 20658                }
 37959            }
 24960            return (queryParams, altServer, transport);
 61        }
 139062    }
 63}

Methods/Properties

ParseQuery(System.Uri)