<commit_before>﻿namespace Rollbar.PayloadScrubbing
{
    using System;
    using System.Diagnostics;
    using Newtonsoft.Json;
    using Newtonsoft.Json.Linq;
    using System.Linq;
    using System.Collections.Generic;
    using System.Text;
    using Rollbar.Serialization.Json;

    /// <summary>
    /// Class RollbarPayloadScrubber.
    /// </summary>
    internal class RollbarPayloadScrubber
    {
        /// <summary>
        /// The scrub mask
        /// </summary>
        private const string scrubMask = "***";
        /// <summary>
        /// The field path root
        /// </summary>
        private const string fieldPathRoot = @"data.";
        /// <summary>
        /// The HTTP request body path
        /// </summary>
        private const string httpRequestBodyPath = "data.body.request.body.";
        /// <summary>
        /// The HTTP response body path
        /// </summary>
        private const string httpResponseBodyPath = "data.body.response.body.";

        /// <summary>
        /// The payload field names
        /// </summary>
        private readonly string[] _payloadFieldNames;
        /// <summary>
        /// The payload field paths
        /// </summary>
        private readonly string[] _payloadFieldPaths;
        /// <summary>
        /// The HTTP request body paths
        /// </summary>
        private readonly string[] _httpRequestBodyPaths;
        /// <summary>
        /// The HTTP response body paths
        /// </summary>
        private readonly string[] _httpResponseBodyPaths;

        /// <summary>
        /// Prevents a default instance of the <see cref="RollbarPayloadScrubber"/> class from being created.
        /// </summary>
        private RollbarPayloadScrubber()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="RollbarPayloadScrubber"/> class.
        /// </summary>
        /// <param name="scrubFields">The scrub fields.</param>
        public RollbarPayloadScrubber(IEnumerable<string> scrubFields)
        {
            this._payloadFieldNames = 
                scrubFields.Where(n => !n.Contains('.'))
                    .ToArray();
            this._payloadFieldPaths = 
                scrubFields.Where(n => n.StartsWith(fieldPathRoot) && !(n.StartsWith(httpRequestBodyPath) || n.StartsWith(httpResponseBodyPath)))
                    .ToArray();
            this._httpRequestBodyPaths = 
                scrubFields.Where(n => n.StartsWith(httpRequestBodyPath))
                    .ToArray();
            this._httpResponseBodyPaths = 
                scrubFields.Where(n => n.StartsWith(httpResponseBodyPath))
                    .ToArray();

            Debug.Assert(scrubFields.Count() == 
                this._payloadFieldNames.Length + 
                this._payloadFieldPaths.Length + 
                this._httpRequestBodyPaths.Length + 
                this._httpResponseBodyPaths.Length
                );
        }

        /// <summary><commit_msg>fixing the root cause of why scrubbing by dotted names did not work<commit_after>﻿namespace Rollbar.PayloadScrubbing
{
    using System;
    using System.Diagnostics;
    using Newtonsoft.Json;
    using Newtonsoft.Json.Linq;
    using System.Linq;
    using System.Collections.Generic;
    using System.Text;
    using Rollbar.Serialization.Json;

    /// <summary>
    /// Class RollbarPayloadScrubber.
    /// </summary>
    internal class RollbarPayloadScrubber
    {
        /// <summary>
        /// The scrub mask
        /// </summary>
        private const string scrubMask = "***";
        /// <summary>
        /// The field path root
        /// </summary>
        private const string fieldPathRoot = @"data.";
        /// <summary>
        /// The HTTP request body path
        /// </summary>
        private const string httpRequestBodyPath = "data.body.request.body.";
        /// <summary>
        /// The HTTP response body path
        /// </summary>
        private const string httpResponseBodyPath = "data.body.response.body.";

        /// <summary>
        /// The payload field names
        /// </summary>
        private readonly string[] _payloadFieldNames;
        /// <summary>
        /// The payload field paths
        /// </summary>
        private readonly string[] _payloadFieldPaths;
        /// <summary>
        /// The HTTP request body paths
        /// </summary>
        private readonly string[] _httpRequestBodyPaths;
        /// <summary>
        /// The HTTP response body paths
        /// </summary>
        private readonly string[] _httpResponseBodyPaths;

        /// <summary>
        /// Prevents a default instance of the <see cref="RollbarPayloadScrubber"/> class from being created.
        /// </summary>
        private RollbarPayloadScrubber()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="RollbarPayloadScrubber"/> class.
        /// </summary>
        /// <param name="scrubFields">The scrub fields.</param>
        public RollbarPayloadScrubber(IEnumerable<string> scrubFields)
        {
            this._payloadFieldNames = 
                scrubFields.Where(n => !( n.StartsWith(fieldPathRoot) || n.StartsWith(httpRequestBodyPath) || n.StartsWith(httpResponseBodyPath)))
                    .ToArray();
            this._payloadFieldPaths = 
                scrubFields.Where(n => n.StartsWith(fieldPathRoot) && !(n.StartsWith(httpRequestBodyPath) || n.StartsWith(httpResponseBodyPath)))
                    .ToArray();
            this._httpRequestBodyPaths = 
                scrubFields.Where(n => n.StartsWith(httpRequestBodyPath))
                    .ToArray();
            this._httpResponseBodyPaths = 
                scrubFields.Where(n => n.StartsWith(httpResponseBodyPath))
                    .ToArray();

            Debug.Assert(scrubFields.Count() == 
                this._payloadFieldNames.Length + 
                this._payloadFieldPaths.Length + 
                this._httpRequestBodyPaths.Length + 
                this._httpResponseBodyPaths.Length
                );
        }

        /// <summary>
{'fraction_non_alphanumeric': 0.11702473958333333, 'fraction_numerical': 0.0, 'mean_word_length': 1.7226406734603457, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3101415', 'n_tokens_mistral': 1550, 'n_tokens_neox': 1522, 'n_words': 351}