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

ThreeMammals / Ocelot / 23302213965

19 Mar 2026 03:19PM UTC coverage: 91.219% (-1.3%) from 92.49%
23302213965

Pull #2369

github

web-flow
Merge 7f6f01146 into 086c7b15c
Pull Request #2369: Pre-Release 25.0 aka Beta 2

8404 of 9213 relevant lines covered (91.22%)

2131.48 hits per line

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

90.32
src/Ocelot/Configuration/Parser/ClaimToThingConfigurationParser.cs
1
using Ocelot.Infrastructure;
2
using Ocelot.Responses;
3

4
namespace Ocelot.Configuration.Parser;
5

6
/// <summary>
7
/// Default implementation of the <see cref="IClaimToThingConfigurationParser"/> interface.
8
/// </summary>
9
public partial class ClaimToThingConfigurationParser : IClaimToThingConfigurationParser
10
{
11
    private const char SplitToken = '>';
12

13
    [GeneratedRegex("Claims\\[.*\\]", RegexOptions.None, RegexGlobal.DefaultMatchTimeoutMilliseconds)]
14
    private static partial Regex ClaimRegex();
15

16
    [GeneratedRegex("value\\[.*\\]", RegexOptions.None, RegexGlobal.DefaultMatchTimeoutMilliseconds)]
17
    private static partial Regex IndexRegex();
18

19
    public Response<ClaimToThing> Extract(string existingKey, string value)
20
    {
4✔
21
        try
22
        {
4✔
23
            var instructions = value.Split(SplitToken);
4✔
24

25
            if (instructions.Length <= 1)
4✔
26
            {
1✔
27
                return new ErrorResponse<ClaimToThing>(new NoInstructionsError(SplitToken.ToString()));
1✔
28
            }
29

30
            var claimMatch = ClaimRegex().IsMatch(instructions[0]);
3✔
31

32
            if (!claimMatch)
3✔
33
            {
1✔
34
                return new ErrorResponse<ClaimToThing>(new InstructionNotForClaimsError());
1✔
35
            }
36

37
            var newKey = GetIndexValue(instructions[0]);
2✔
38
            var index = 0;
2✔
39
            var delimiter = string.Empty;
2✔
40

41
            if (instructions.Length > 2 && IndexRegex().IsMatch(instructions[1]))
2✔
42
            {
1✔
43
                index = int.Parse(GetIndexValue(instructions[1]));
1✔
44
                delimiter = instructions[2].Trim();
1✔
45
            }
1✔
46

47
            return new OkResponse<ClaimToThing>(
2✔
48
                           new ClaimToThing(existingKey, newKey, delimiter, index));
2✔
49
        }
50
        catch (Exception exception)
×
51
        {
×
52
            return new ErrorResponse<ClaimToThing>(new ParsingConfigurationHeaderError(exception));
×
53
        }
54
    }
4✔
55

56
    private static string GetIndexValue(string instruction)
57
    {
3✔
58
        var firstIndexer = instruction.IndexOf('[', StringComparison.Ordinal);
3✔
59
        var lastIndexer = instruction.IndexOf(']', StringComparison.Ordinal);
3✔
60
        var length = lastIndexer - firstIndexer;
3✔
61
        var claimKey = instruction.Substring(firstIndexer + 1, length - 1);
3✔
62
        return claimKey;
3✔
63
    }
3✔
64
}
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

© 2026 Coveralls, Inc