• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

stripe / stripe-dotnet / 11519002614

25 Oct 2024 01:18PM UTC coverage: 46.558% (-0.05%) from 46.606%
11519002614

Pull #3011

coveralls.net

web-flow
Merge e47f89dd2 into 2c30f9d61
Pull Request #3011: Do not allow setting API Version directly on StripeConfiguration

5194 of 11156 relevant lines covered (46.56%)

96.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

62.86
/src/Stripe.net/Infrastructure/StringUtils.cs
1
namespace Stripe.Infrastructure
2
{
3
    using System;
4
    using System.Runtime.CompilerServices;
5
    using System.Text.RegularExpressions;
6

7
    internal static class StringUtils
8
    {
9
        private static Regex whitespaceRegex = new Regex(@"\s", RegexOptions.CultureInvariant);
1✔
10

11
        /// <summary>Converts the string to snake case.</summary>
12
        /// <param name="str">The string to convert.</param>
13
        /// <returns>A string with the contents of the input string converted to snake_case.</returns>
14
        public static string ToSnakeCase(string str)
15
        {
8✔
16
            var tmp = Regex.Replace(str, "(.)([A-Z][a-z]+)", "$1_$2");
8✔
17
            return Regex.Replace(tmp, "([a-z0-9])([A-Z])", "$1_$2").ToLower();
8✔
18
        }
8✔
19

20
        /// <summary>
21
        /// Determines whether the two specified <see cref="string"/> objects have the same value.
22
        /// The comparison is done in constant time to prevent timing attacks.
23
        /// </summary>
24
        /// <param name="a">The first string to compare.</param>
25
        /// <param name="b">The second string to compare.</param>
26
        /// <returns>
27
        /// <c>true</c> if the value of the <c>a</c> parameter is equal to the value of the <c>b</c>
28
        /// parameter; otherwise, <c>false</c>.
29
        /// </returns>
30
        [MethodImpl(MethodImplOptions.NoOptimization)]
31
        public static bool SecureEquals(string a, string b)
32
        {
27✔
33
            if (a == null)
27✔
34
            {
×
35
                throw new ArgumentNullException(nameof(a));
×
36
            }
37

38
            if (b == null)
27✔
39
            {
×
40
                throw new ArgumentNullException(nameof(b));
×
41
            }
42

43
            if (a.Length != b.Length)
27✔
44
            {
5✔
45
                return false;
5✔
46
            }
47

48
            var result = 0;
22✔
49

50
            for (var i = 0; i < a.Length; i++)
2,496✔
51
            {
1,226✔
52
                result |= a[i] ^ b[i];
1,226✔
53
            }
1,226✔
54

55
            return result == 0;
22✔
56
        }
27✔
57

58
        /// <summary>Checks whether a string contains any whitespace characters or not.</summary>
59
        /// <param name="str">The string to check.</param>
60
        /// <returns>
61
        /// <c>true</c> if the string contains any whitespace characters; otherwise, <c>false</c>.
62
        /// </returns>
63
        /// <exception name="ArgumentNullException">Thrown if <c>str</c> is <c>null</c>.</exception>
64
        public static bool ContainsWhitespace(string str)
65
        {
1,623✔
66
            if (str == null)
1,623✔
67
            {
×
68
                throw new ArgumentNullException(nameof(str));
×
69
            }
70

71
            return whitespaceRegex.IsMatch(str);
1,623✔
72
        }
1,623✔
73

74
        /// <summary>
75
        /// Trims the beta header part of an API Version string.
76
        /// For example, "12-22-2022; orders_beta=v3" is converted to "12-22-2022".
77
        /// </summary>
78
        /// <param name="apiVersion">The API Version to trim. For example, "12-22-2022; orders_beta=v3".</param>
79
        /// <returns>The trimmed API Version string. For example, "12-22-2022".</returns>
80
        public static string TrimApiVersion(string apiVersion)
81
        {
×
82
            var indexOfSemicolon = apiVersion?.IndexOf(';');
×
83
            if (indexOfSemicolon > -1)
×
84
            {
×
85
                return apiVersion.Substring(0, indexOfSemicolon.Value);
×
86
            }
87

88
            return apiVersion;
×
89
        }
×
90
    }
91
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc