< Summary

Information
Class: TeleFlow.Telegram.Internal.TelegramDeepLinkPayloadValidator
Assembly: TeleFlow.Telegram.Client
File(s): /_/src/TeleFlow.Telegram.Client/Internal/TelegramDeepLinkPayloadValidator.cs
Line coverage
100%
Covered lines: 16
Uncovered lines: 0
Coverable lines: 16
Total lines: 39
Line coverage: 100%
Branch coverage
95%
Covered branches: 19
Total branches: 20
Branch coverage: 95%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Validate(...)100%66100%
IsDeepLinkPayloadCharacter(...)92.85%1414100%

File(s)

/_/src/TeleFlow.Telegram.Client/Internal/TelegramDeepLinkPayloadValidator.cs

#LineLine coverage
 1using System.Text;
 2
 3namespace TeleFlow.Telegram.Internal;
 4
 5internal static class TelegramDeepLinkPayloadValidator
 6{
 7    public const int PayloadByteLimit = 64;
 8
 9    public static void Validate(string payload)
 10    {
 2111        ArgumentException.ThrowIfNullOrWhiteSpace(payload);
 12
 1913        var byteCount = Encoding.UTF8.GetByteCount(payload);
 1914        if (byteCount > PayloadByteLimit)
 15        {
 116            throw new ArgumentException(
 117                $"Telegram deep-link payload must be at most {PayloadByteLimit} UTF-8 bytes.",
 118                nameof(payload));
 19        }
 20
 39821        foreach (var character in payload)
 22        {
 18223            if (!IsDeepLinkPayloadCharacter(character))
 24            {
 225                throw new ArgumentException(
 226                    "Telegram deep-link payload can contain only ASCII letters, digits, '-' and '_'.",
 227                    nameof(payload));
 28            }
 29        }
 1630    }
 31
 32    private static bool IsDeepLinkPayloadCharacter(char character)
 33    {
 18234        return character is >= 'A' and <= 'Z' ||
 18235               character is >= 'a' and <= 'z' ||
 18236               character is >= '0' and <= '9' ||
 18237               character is '-' or '_';
 38    }
 39}