<commit_before>// Copyright (c) <NAME>. See License.txt in the project root for license information.

using System;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace NWebsec.Core.HttpHeaders.Csp
{
    public class CspUriSource
    {
        private const string HostRegex = @"^(\*\.)?([\p{Ll}\p{Lu}0-9\-]+)(\.[\p{Ll}\p{Lu}0-9\-]+)*$";
        private static readonly string SchemeOnlyRegex = "^[a-zA-Z]*[a-zA-Z0-9" + Regex.Escape("+.-") + "]:$";
        private static readonly string[] KnownSchemes = { "http", "https", "data", "ws", "wss" };
        private readonly string _source;

        private CspUriSource(string source)
        {
            _source = source;
        }

        // Returns the source as a string encoded according to the CSP spec.
        public override string ToString()
        {
            return _source;

        }

        public static string EncodeUri(Uri uri)
        {

            if (!uri.IsAbsoluteUri)
            {
                var uriString = uri.IsWellFormedOriginalString() ? uri.ToString() : Uri.EscapeUriString(uri.ToString());
                return EscapeReservedCspChars(uriString);
            }

            var host = uri.Host;
            var encodedHost = EncodeHostname(host);

            var needsReplacement = !host.Equals(encodedHost);

            var authority = uri.GetComponents(UriComponents.SchemeAndServer, UriFormat.SafeUnescaped);<commit_msg>Update the NWebsec internal bits to apply a bug fix<commit_after>// Copyright (c) <NAME>. See License.txt in the project root for license information.

using System;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace NWebsec.Core.HttpHeaders.Csp
{
    public class CspUriSource
    {
        private const string HostRegex = @"^(\*\.)?([\p{Ll}\p{Lu}0-9\-]+)(\.[\p{Ll}\p{Lu}0-9\-]+)*$";
        private static readonly string SchemeOnlyRegex = "^[a-zA-Z]*[a-zA-Z0-9" + Regex.Escape("+.-") + "]:$";
        private static readonly string[] KnownSchemes = { "http", "https", "ws", "wss" };
        private readonly string _source;

        private CspUriSource(string source)
        {
            _source = source;
        }

        // Returns the source as a string encoded according to the CSP spec.
        public override string ToString()
        {
            return _source;

        }

        public static string EncodeUri(Uri uri)
        {

            if (!uri.IsAbsoluteUri)
            {
                var uriString = uri.IsWellFormedOriginalString() ? uri.ToString() : Uri.EscapeUriString(uri.ToString());
                return EscapeReservedCspChars(uriString);
            }

            var host = uri.Host;
            var encodedHost = EncodeHostname(host);

            var needsReplacement = !host.Equals(encodedHost);

            var authority = uri.GetComponents(UriComponents.SchemeAndServer, UriFormat.SafeUnescaped);
{'fraction_non_alphanumeric': 0.12266042780748664, 'fraction_numerical': 0.004010695187165776, 'mean_word_length': 2.3667041619797526, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4887727', 'n_tokens_mistral': 891, 'n_tokens_neox': 846, 'n_words': 215}