You've already forked linux-packaging-mono
Imported Upstream version 4.6.0.125
Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
parent
a569aebcfd
commit
e79aa3c0ed
@@ -0,0 +1 @@
|
||||
6fc96d5a48329aa8e7ef17bceda3f17990c6df42
|
@@ -0,0 +1,198 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="ADMembershipUser.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.Security {
|
||||
using System.Web;
|
||||
using System.Web.Configuration;
|
||||
using System.Security.Principal;
|
||||
using System.Security.Permissions;
|
||||
using System.Globalization;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Diagnostics;
|
||||
|
||||
[Serializable]
|
||||
public class ActiveDirectoryMembershipUser : MembershipUser
|
||||
{
|
||||
|
||||
internal bool emailModified = true;
|
||||
internal bool commentModified = true;
|
||||
internal bool isApprovedModified = true;
|
||||
|
||||
//
|
||||
// private variables needed for the providerUserKey
|
||||
// (We need to store the provider user key here rather than the base class
|
||||
// to be able to do custom serialization)
|
||||
//
|
||||
private byte[] sidBinaryForm = null;
|
||||
[NonSerialized]
|
||||
private SecurityIdentifier sid = null;
|
||||
|
||||
public override DateTime LastLoginDate
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException(SR.GetString(SR.ADMembership_UserProperty_not_supported, "LastLoginDate"));
|
||||
}
|
||||
set
|
||||
{
|
||||
throw new NotSupportedException(SR.GetString(SR.ADMembership_UserProperty_not_supported, "LastLoginDate"));
|
||||
}
|
||||
}
|
||||
|
||||
public override DateTime LastActivityDate
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException(SR.GetString(SR.ADMembership_UserProperty_not_supported, "LastActivityDate"));
|
||||
}
|
||||
set
|
||||
{
|
||||
throw new NotSupportedException(SR.GetString(SR.ADMembership_UserProperty_not_supported, "LastActivityDate"));
|
||||
}
|
||||
}
|
||||
|
||||
public override string Email
|
||||
{
|
||||
get
|
||||
{
|
||||
return base.Email;
|
||||
}
|
||||
set
|
||||
{
|
||||
base.Email = value;
|
||||
emailModified = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override string Comment
|
||||
{
|
||||
get
|
||||
{
|
||||
return base.Comment;
|
||||
}
|
||||
set
|
||||
{
|
||||
base.Comment = value;
|
||||
commentModified = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool IsApproved
|
||||
{
|
||||
get
|
||||
{
|
||||
return base.IsApproved;
|
||||
}
|
||||
set
|
||||
{
|
||||
base.IsApproved = value;
|
||||
isApprovedModified = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override object ProviderUserKey
|
||||
{
|
||||
get
|
||||
{
|
||||
if (sid == null && sidBinaryForm != null)
|
||||
sid = new SecurityIdentifier(sidBinaryForm, 0);
|
||||
return sid;
|
||||
}
|
||||
}
|
||||
|
||||
public ActiveDirectoryMembershipUser(string providerName,
|
||||
string name,
|
||||
object providerUserKey,
|
||||
string email,
|
||||
string passwordQuestion,
|
||||
string comment,
|
||||
bool isApproved,
|
||||
bool isLockedOut,
|
||||
DateTime creationDate,
|
||||
DateTime lastLoginDate,
|
||||
DateTime lastActivityDate,
|
||||
DateTime lastPasswordChangedDate,
|
||||
DateTime lastLockoutDate)
|
||||
:base(providerName,
|
||||
name,
|
||||
null,
|
||||
email,
|
||||
passwordQuestion,
|
||||
comment,
|
||||
isApproved,
|
||||
isLockedOut,
|
||||
creationDate,
|
||||
lastLoginDate,
|
||||
lastActivityDate,
|
||||
lastPasswordChangedDate,
|
||||
lastLockoutDate)
|
||||
{
|
||||
if ((providerUserKey != null) && !(providerUserKey is SecurityIdentifier))
|
||||
throw new ArgumentException( SR.GetString(SR.ADMembership_InvalidProviderUserKey) , "providerUserKey" );
|
||||
|
||||
sid = (SecurityIdentifier) providerUserKey;
|
||||
if (sid != null)
|
||||
{
|
||||
//
|
||||
// store the sid in binary form for serialization
|
||||
//
|
||||
sidBinaryForm = new byte[sid.BinaryLength];
|
||||
sid.GetBinaryForm(sidBinaryForm, 0);
|
||||
}
|
||||
}
|
||||
|
||||
internal ActiveDirectoryMembershipUser(string providerName,
|
||||
string name,
|
||||
byte[] sidBinaryForm,
|
||||
object providerUserKey,
|
||||
string email,
|
||||
string passwordQuestion,
|
||||
string comment,
|
||||
bool isApproved,
|
||||
bool isLockedOut,
|
||||
DateTime creationDate,
|
||||
DateTime lastLoginDate,
|
||||
DateTime lastActivityDate,
|
||||
DateTime lastPasswordChangedDate,
|
||||
DateTime lastLockoutDate,
|
||||
bool valuesAreUpdated)
|
||||
:base(providerName,
|
||||
name,
|
||||
null,
|
||||
email,
|
||||
passwordQuestion,
|
||||
comment,
|
||||
isApproved,
|
||||
isLockedOut,
|
||||
creationDate,
|
||||
lastLoginDate,
|
||||
lastActivityDate,
|
||||
lastPasswordChangedDate,
|
||||
lastLockoutDate)
|
||||
{
|
||||
|
||||
if (valuesAreUpdated)
|
||||
{
|
||||
emailModified = false;
|
||||
commentModified = false;
|
||||
isApprovedModified = false;
|
||||
}
|
||||
|
||||
Debug.Assert(sidBinaryForm != null);
|
||||
this.sidBinaryForm = sidBinaryForm;
|
||||
|
||||
Debug.Assert((providerUserKey != null) && (providerUserKey is SecurityIdentifier));
|
||||
sid = (SecurityIdentifier) providerUserKey;
|
||||
|
||||
}
|
||||
|
||||
protected ActiveDirectoryMembershipUser() { } // Default CTor: Callable by derived class only.
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -0,0 +1,425 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="AnonymousIdentificationModule.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* AnonymousIdentificationModule class
|
||||
*
|
||||
* Copyright (c) 1999 Microsoft Corporation
|
||||
*/
|
||||
|
||||
namespace System.Web.Security {
|
||||
using System.Web;
|
||||
using System.Text;
|
||||
using System.Web.Configuration;
|
||||
using System.Web.Caching;
|
||||
using System.Web.Handlers;
|
||||
using System.Collections;
|
||||
using System.Configuration.Provider;
|
||||
using System.Web.Util;
|
||||
using System.Security.Principal;
|
||||
using System.Security.Permissions;
|
||||
using System.Globalization;
|
||||
using System.Web.Management;
|
||||
using System.Web.Hosting;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.Web.Security.Cryptography;
|
||||
|
||||
/// <devdoc>
|
||||
/// <para>[To be supplied.]</para>
|
||||
/// </devdoc>
|
||||
public sealed class AnonymousIdentificationModule : IHttpModule {
|
||||
|
||||
private const int MAX_ENCODED_COOKIE_STRING = 512;
|
||||
private const int MAX_ID_LENGTH = 128;
|
||||
|
||||
/// <devdoc>
|
||||
/// <para>
|
||||
/// Initializes a new instance of the <see cref='System.Web.Security.AnonymousIdentificationModule'/>
|
||||
/// class.
|
||||
/// </para>
|
||||
/// </devdoc>
|
||||
[SecurityPermission(SecurityAction.Demand, Unrestricted=true)]
|
||||
public AnonymousIdentificationModule() {
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Events
|
||||
private AnonymousIdentificationEventHandler _CreateNewIdEventHandler;
|
||||
|
||||
public event AnonymousIdentificationEventHandler Creating {
|
||||
add { _CreateNewIdEventHandler += value; }
|
||||
remove { _CreateNewIdEventHandler -= value; }
|
||||
}
|
||||
|
||||
public static void ClearAnonymousIdentifier()
|
||||
{
|
||||
if (!s_Initialized)
|
||||
Initialize();
|
||||
|
||||
HttpContext context = HttpContext.Current;
|
||||
if (context == null)
|
||||
return;
|
||||
|
||||
// VSWhidbey 418835: When this feature is enabled, prevent infinite loop when cookieless
|
||||
// mode != Cookies and there was no cookie, also we cannot clear when current user is anonymous.
|
||||
if (!s_Enabled || !context.Request.IsAuthenticated) {
|
||||
throw new NotSupportedException(SR.GetString(SR.Anonymous_ClearAnonymousIdentifierNotSupported));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Check if we need to clear the ticket stored in the URI
|
||||
bool clearUri = false;
|
||||
if (context.CookielessHelper.GetCookieValue('A') != null) {
|
||||
context.CookielessHelper.SetCookieValue('A', null); // Always clear the uri-cookie
|
||||
clearUri = true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Clear cookie if cookies are supported by the browser
|
||||
if (!CookielessHelperClass.UseCookieless(context, false, s_CookieMode) || context.Request.Browser.Cookies)
|
||||
{ // clear cookie if required
|
||||
string cookieValue = String.Empty;
|
||||
if (context.Request.Browser["supportsEmptyStringInCookieValue"] == "false")
|
||||
cookieValue = "NoCookie";
|
||||
HttpCookie cookie = new HttpCookie(s_CookieName, cookieValue);
|
||||
cookie.HttpOnly = true;
|
||||
cookie.Path = s_CookiePath;
|
||||
cookie.Secure = s_RequireSSL;
|
||||
if (s_Domain != null)
|
||||
cookie.Domain = s_Domain;
|
||||
cookie.Expires = new System.DateTime(1999, 10, 12);
|
||||
context.Response.Cookies.RemoveCookie(s_CookieName);
|
||||
context.Response.Cookies.Add(cookie);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Redirect back to this page if we removed a URI ticket
|
||||
if (clearUri) {
|
||||
context.Response.Redirect(context.Request.RawUrl, false);
|
||||
}
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Public functions
|
||||
|
||||
public void Dispose() { }
|
||||
|
||||
public void Init(HttpApplication app) {
|
||||
// for IIS 7, skip event wireup altogether if this feature isn't
|
||||
// enabled
|
||||
if (!s_Initialized) {
|
||||
Initialize();
|
||||
}
|
||||
if (s_Enabled) {
|
||||
app.PostAuthenticateRequest += new EventHandler(this.OnEnter);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
/// <devdoc>
|
||||
/// <para>[To be supplied.]</para>
|
||||
/// </devdoc>
|
||||
private void OnEnter(Object source, EventArgs eventArgs) {
|
||||
if (!s_Initialized)
|
||||
Initialize();
|
||||
|
||||
if (!s_Enabled)
|
||||
return;
|
||||
|
||||
HttpApplication app;
|
||||
HttpContext context;
|
||||
HttpCookie cookie = null;
|
||||
bool createCookie = false;
|
||||
AnonymousIdData decodedValue = null;
|
||||
bool cookieLess;
|
||||
string encValue = null;
|
||||
bool isAuthenticated = false;
|
||||
|
||||
app = (HttpApplication)source;
|
||||
context = app.Context;
|
||||
|
||||
isAuthenticated = context.Request.IsAuthenticated;
|
||||
|
||||
if (isAuthenticated) {
|
||||
cookieLess = CookielessHelperClass.UseCookieless(context, false /* no redirect */, s_CookieMode);
|
||||
} else {
|
||||
cookieLess = CookielessHelperClass.UseCookieless(context, true /* do redirect */, s_CookieMode);
|
||||
//if (!cookieLess && s_RequireSSL && !context.Request.IsSecureConnection)
|
||||
// throw new HttpException(SR.GetString(SR.Connection_not_secure_creating_secure_cookie));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Handle secure-cookies over non SSL
|
||||
if (s_RequireSSL && !context.Request.IsSecureConnection)
|
||||
{
|
||||
if (!cookieLess)
|
||||
{
|
||||
cookie = context.Request.Cookies[s_CookieName];
|
||||
if (cookie != null)
|
||||
{
|
||||
cookie = new HttpCookie(s_CookieName, String.Empty);
|
||||
cookie.HttpOnly = true;
|
||||
cookie.Path = s_CookiePath;
|
||||
cookie.Secure = s_RequireSSL;
|
||||
if (s_Domain != null)
|
||||
cookie.Domain = s_Domain;
|
||||
cookie.Expires = new System.DateTime(1999, 10, 12);
|
||||
|
||||
if (context.Request.Browser["supportsEmptyStringInCookieValue"] == "false")
|
||||
cookie.Value = "NoCookie";
|
||||
context.Response.Cookies.Add(cookie);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Step 2: See if cookie, or cookie-header has the value
|
||||
if (!cookieLess)
|
||||
{
|
||||
cookie = context.Request.Cookies[s_CookieName];
|
||||
if (cookie != null)
|
||||
{
|
||||
encValue = cookie.Value;
|
||||
cookie.Path = s_CookiePath;
|
||||
if (s_Domain != null)
|
||||
cookie.Domain = s_Domain;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
encValue = context.CookielessHelper.GetCookieValue('A');
|
||||
}
|
||||
|
||||
decodedValue = GetDecodedValue(encValue);
|
||||
|
||||
if (decodedValue != null && decodedValue.AnonymousId != null) {
|
||||
// Copy existing value in Request
|
||||
context.Request.AnonymousID = decodedValue.AnonymousId;
|
||||
}
|
||||
if (isAuthenticated) // For the authenticated case, we are done
|
||||
return;
|
||||
|
||||
if (context.Request.AnonymousID == null) {
|
||||
////////////////////////////////////////////////////////////
|
||||
// Step 3: Create new Identity
|
||||
|
||||
// Raise event
|
||||
if (_CreateNewIdEventHandler != null) {
|
||||
AnonymousIdentificationEventArgs e = new AnonymousIdentificationEventArgs(context);
|
||||
_CreateNewIdEventHandler(this, e);
|
||||
context.Request.AnonymousID = e.AnonymousID;
|
||||
}
|
||||
|
||||
// Create from GUID
|
||||
if (string.IsNullOrEmpty(context.Request.AnonymousID)) {
|
||||
context.Request.AnonymousID = Guid.NewGuid().ToString("D", CultureInfo.InvariantCulture);
|
||||
} else {
|
||||
if (context.Request.AnonymousID.Length > MAX_ID_LENGTH)
|
||||
throw new HttpException(SR.GetString(SR.Anonymous_id_too_long));
|
||||
}
|
||||
if (s_RequireSSL && !context.Request.IsSecureConnection && !cookieLess)
|
||||
return; // Don't create secure-cookie in un-secured connection
|
||||
|
||||
createCookie = true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Step 4: Check if cookie has to be created
|
||||
DateTime dtNow = DateTime.UtcNow;
|
||||
if (!createCookie) {
|
||||
if (s_SlidingExpiration) {
|
||||
if (decodedValue == null || decodedValue.ExpireDate < dtNow) {
|
||||
createCookie = true;
|
||||
} else {
|
||||
double secondsLeft = (decodedValue.ExpireDate - dtNow).TotalSeconds;
|
||||
if (secondsLeft < (double) ((s_CookieTimeout*60)/2)) {
|
||||
createCookie = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Step 4: Create new cookie or cookieless header
|
||||
if (createCookie) {
|
||||
DateTime dtExpireTime = dtNow.AddMinutes(s_CookieTimeout);
|
||||
encValue = GetEncodedValue(new AnonymousIdData(context.Request.AnonymousID, dtExpireTime));
|
||||
if (encValue.Length > MAX_ENCODED_COOKIE_STRING)
|
||||
throw new HttpException(SR.GetString(SR.Anonymous_id_too_long_2));
|
||||
|
||||
if (!cookieLess) {
|
||||
cookie = new HttpCookie(s_CookieName, encValue);
|
||||
cookie.HttpOnly = true;
|
||||
cookie.Expires = dtExpireTime;
|
||||
cookie.Path = s_CookiePath;
|
||||
cookie.Secure = s_RequireSSL;
|
||||
if (s_Domain != null)
|
||||
cookie.Domain = s_Domain;
|
||||
context.Response.Cookies.Add(cookie);
|
||||
} else {
|
||||
context.CookielessHelper.SetCookieValue('A', encValue);
|
||||
context.Response.Redirect(context.Request.RawUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool Enabled {
|
||||
get {
|
||||
if (!s_Initialized) {
|
||||
Initialize();
|
||||
}
|
||||
return s_Enabled;
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Static config settings
|
||||
private static bool s_Initialized = false;
|
||||
private static bool s_Enabled = false;
|
||||
private static string s_CookieName = ".ASPXANONYMOUS";
|
||||
private static string s_CookiePath = "/";
|
||||
private static int s_CookieTimeout = 100000;
|
||||
private static bool s_RequireSSL = false;
|
||||
private static string s_Domain = null;
|
||||
private static bool s_SlidingExpiration = true;
|
||||
private static byte [] s_Modifier = null;
|
||||
private static object s_InitLock = new object();
|
||||
private static HttpCookieMode s_CookieMode = HttpCookieMode.UseDeviceProfile;
|
||||
private static CookieProtection s_Protection = CookieProtection.None;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Static functions
|
||||
private static void Initialize() {
|
||||
|
||||
if (s_Initialized)
|
||||
return;
|
||||
|
||||
lock(s_InitLock) {
|
||||
if (s_Initialized)
|
||||
return;
|
||||
|
||||
AnonymousIdentificationSection settings = RuntimeConfig.GetAppConfig().AnonymousIdentification;
|
||||
s_Enabled = settings.Enabled;
|
||||
s_CookieName = settings.CookieName;
|
||||
s_CookiePath = settings.CookiePath;
|
||||
s_CookieTimeout = (int) settings.CookieTimeout.TotalMinutes;
|
||||
s_RequireSSL = settings.CookieRequireSSL;
|
||||
s_SlidingExpiration = settings.CookieSlidingExpiration;
|
||||
s_Protection = settings.CookieProtection;
|
||||
s_CookieMode = settings.Cookieless;
|
||||
s_Domain = settings.Domain;
|
||||
|
||||
s_Modifier = Encoding.UTF8.GetBytes("AnonymousIdentification");
|
||||
if (s_CookieTimeout < 1)
|
||||
s_CookieTimeout = 1;
|
||||
if (s_CookieTimeout > 60 * 24 * 365 * 2)
|
||||
s_CookieTimeout = 60 * 24 * 365 * 2; // 2 years
|
||||
s_Initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
private static string GetEncodedValue(AnonymousIdData data){
|
||||
if (data == null)
|
||||
return null;
|
||||
byte [] bufId = Encoding.UTF8.GetBytes(data.AnonymousId);
|
||||
byte [] bufIdLen = BitConverter.GetBytes(bufId.Length);
|
||||
byte [] bufDate = BitConverter.GetBytes(data.ExpireDate.ToFileTimeUtc());
|
||||
byte [] buffer = new byte[12 + bufId.Length];
|
||||
|
||||
Buffer.BlockCopy(bufDate, 0, buffer, 0, 8);
|
||||
Buffer.BlockCopy(bufIdLen, 0, buffer, 8, 4);
|
||||
Buffer.BlockCopy(bufId, 0, buffer, 12, bufId.Length);
|
||||
return CookieProtectionHelper.Encode(s_Protection, buffer, Purpose.AnonymousIdentificationModule_Ticket);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
private static AnonymousIdData GetDecodedValue(string data){
|
||||
if (data == null || data.Length < 1 || data.Length > MAX_ENCODED_COOKIE_STRING)
|
||||
return null;
|
||||
|
||||
try {
|
||||
byte [] bBlob = CookieProtectionHelper.Decode(s_Protection, data, Purpose.AnonymousIdentificationModule_Ticket);
|
||||
if (bBlob == null || bBlob.Length < 13)
|
||||
return null;
|
||||
DateTime expireDate = DateTime.FromFileTimeUtc(BitConverter.ToInt64(bBlob, 0));
|
||||
if (expireDate < DateTime.UtcNow)
|
||||
return null;
|
||||
int len = BitConverter.ToInt32(bBlob, 8);
|
||||
if (len < 0 || len > bBlob.Length - 12)
|
||||
return null;
|
||||
string id = Encoding.UTF8.GetString(bBlob, 12, len);
|
||||
if (id.Length > MAX_ID_LENGTH)
|
||||
return null;
|
||||
return new AnonymousIdData(id, expireDate);
|
||||
}
|
||||
catch {}
|
||||
return null;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
[Serializable]
|
||||
internal class AnonymousIdData
|
||||
{
|
||||
internal AnonymousIdData(string id, DateTime dt) {
|
||||
ExpireDate = dt;
|
||||
AnonymousId = (dt > DateTime.UtcNow) ? id : null; // Ignore expired data
|
||||
}
|
||||
|
||||
internal string AnonymousId;
|
||||
internal DateTime ExpireDate;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public delegate void AnonymousIdentificationEventHandler(object sender, AnonymousIdentificationEventArgs e);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public sealed class AnonymousIdentificationEventArgs : EventArgs {
|
||||
|
||||
public string AnonymousID { get { return _AnonymousId;} set { _AnonymousId = value;}}
|
||||
|
||||
public HttpContext Context { get { return _Context; }}
|
||||
|
||||
private string _AnonymousId;
|
||||
private HttpContext _Context;
|
||||
|
||||
|
||||
public AnonymousIdentificationEventArgs(HttpContext context) {
|
||||
_Context = context;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,144 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="AntiXssEncoder.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.Security.AntiXss {
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Web.Hosting;
|
||||
using System.Web.Util;
|
||||
|
||||
public class AntiXssEncoder : HttpEncoder {
|
||||
|
||||
#region HttpEncoder Methods
|
||||
|
||||
// NOTE: No Anti-XSS equivalents for HtmlDecode and HeaderNameValueEncode
|
||||
|
||||
protected internal override void HtmlAttributeEncode(string value, TextWriter output) {
|
||||
if (output == null) {
|
||||
throw new ArgumentNullException("output");
|
||||
}
|
||||
|
||||
output.Write(UnicodeCharacterEncoder.HtmlAttributeEncode(value));
|
||||
}
|
||||
|
||||
protected internal override void HtmlEncode(string value, TextWriter output) {
|
||||
if (output == null) {
|
||||
throw new ArgumentNullException("output");
|
||||
}
|
||||
|
||||
output.Write(HtmlEncode(value, false));
|
||||
}
|
||||
|
||||
protected internal override byte[] UrlEncode(byte[] bytes, int offset, int count) {
|
||||
if (!HttpEncoder.ValidateUrlEncodingParameters(bytes, offset, count)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
string utf8String = Encoding.UTF8.GetString(bytes, offset, count);
|
||||
string result = UrlEncode(utf8String, Encoding.UTF8);
|
||||
return Encoding.UTF8.GetBytes(result);
|
||||
}
|
||||
|
||||
protected internal override string UrlPathEncode(string value) {
|
||||
if (String.IsNullOrEmpty(value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
// DevDiv #211105: We should make the UrlPathEncode method encode only the path portion of URLs.
|
||||
|
||||
string schemeAndAuthority;
|
||||
string path;
|
||||
string queryAndFragment;
|
||||
bool isValidUrl = UriUtil.TrySplitUriForPathEncode(value, out schemeAndAuthority, out path, out queryAndFragment, checkScheme: false);
|
||||
|
||||
if (!isValidUrl) {
|
||||
// treat as a relative URL, so we might still need to chop off the query / fragment components
|
||||
schemeAndAuthority = null;
|
||||
UriUtil.ExtractQueryAndFragment(value, out path, out queryAndFragment);
|
||||
}
|
||||
|
||||
return schemeAndAuthority + HtmlParameterEncoder.UrlPathEncode(path, Encoding.UTF8) + queryAndFragment;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public static void MarkAsSafe(LowerCodeCharts lowerCodeCharts, LowerMidCodeCharts lowerMidCodeCharts,
|
||||
MidCodeCharts midCodeCharts, UpperMidCodeCharts upperMidCodeCharts, UpperCodeCharts upperCodeCharts) {
|
||||
|
||||
// should be callable from console apps
|
||||
if (HostingEnvironment.IsHosted) {
|
||||
HttpApplicationFactory.ThrowIfApplicationOnStartCalled();
|
||||
}
|
||||
|
||||
UnicodeCharacterEncoder.MarkAsSafe(lowerCodeCharts, lowerMidCodeCharts, midCodeCharts, upperMidCodeCharts, upperCodeCharts);
|
||||
}
|
||||
|
||||
public static string CssEncode(string input) {
|
||||
return CssEncoder.Encode(input);
|
||||
}
|
||||
|
||||
public static string HtmlEncode(string input, bool useNamedEntities) {
|
||||
return UnicodeCharacterEncoder.HtmlEncode(input, useNamedEntities);
|
||||
}
|
||||
|
||||
[SuppressMessage("Microsoft.Design", "CA1055:UriReturnValuesShouldNotBeStrings",
|
||||
Justification = "As this is meant as a replacement for HttpUility.Encode we must keep the same return type.")]
|
||||
public static string UrlEncode(string input) {
|
||||
return UrlEncode(input, Encoding.UTF8);
|
||||
}
|
||||
|
||||
[SuppressMessage("Microsoft.Design", "CA1055:UriReturnValuesShouldNotBeStrings",
|
||||
Justification = "This does not return a URL so the return type can be a string.")]
|
||||
public static string HtmlFormUrlEncode(string input) {
|
||||
return HtmlFormUrlEncode(input, Encoding.UTF8);
|
||||
}
|
||||
|
||||
[SuppressMessage("Microsoft.Design", "CA1055:UriReturnValuesShouldNotBeStrings",
|
||||
Justification = "This does not return a URL so the return type can be a string.")]
|
||||
public static string UrlEncode(string input, int codePage) {
|
||||
return UrlEncode(input, Encoding.GetEncoding(codePage));
|
||||
}
|
||||
|
||||
[SuppressMessage("Microsoft.Design", "CA1055:UriReturnValuesShouldNotBeStrings",
|
||||
Justification = "This does not return a URL so the return type can be a string.")]
|
||||
public static string HtmlFormUrlEncode(string input, int codePage) {
|
||||
return HtmlFormUrlEncode(input, Encoding.GetEncoding(codePage));
|
||||
}
|
||||
|
||||
[SuppressMessage("Microsoft.Design", "CA1055:UriReturnValuesShouldNotBeStrings",
|
||||
Justification = "This does not return a URL so the return type can be a string.")]
|
||||
public static string UrlEncode(string input, Encoding inputEncoding) {
|
||||
// Assuming the default to be UTF-8
|
||||
if (inputEncoding == null) {
|
||||
inputEncoding = Encoding.UTF8;
|
||||
}
|
||||
|
||||
return HtmlParameterEncoder.QueryStringParameterEncode(input, inputEncoding);
|
||||
}
|
||||
|
||||
[SuppressMessage("Microsoft.Design", "CA1055:UriReturnValuesShouldNotBeStrings",
|
||||
Justification = "This does not return a URL so the return type can be a string.")]
|
||||
public static string HtmlFormUrlEncode(string input, Encoding inputEncoding) {
|
||||
// Assuming the default to be UTF-8
|
||||
if (inputEncoding == null) {
|
||||
inputEncoding = Encoding.UTF8;
|
||||
}
|
||||
|
||||
return HtmlParameterEncoder.FormStringParameterEncode(input, inputEncoding);
|
||||
}
|
||||
|
||||
public static string XmlEncode(string input) {
|
||||
return UnicodeCharacterEncoder.XmlEncode(input);
|
||||
}
|
||||
|
||||
public static string XmlAttributeEncode(string input) {
|
||||
// HtmlEncodeAttribute will handle input
|
||||
return UnicodeCharacterEncoder.XmlAttributeEncode(input);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,28 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="CodeChartHelper.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.Security.AntiXss.CodeCharts {
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
|
||||
internal static class CodeChartHelper {
|
||||
internal static IEnumerable<int> GetRange(int min, int max, Func<int, bool> exclusionFilter) {
|
||||
Debug.Assert(min <= max);
|
||||
|
||||
var range = Enumerable.Range(min, (max - min + 1));
|
||||
if (exclusionFilter != null) {
|
||||
range = range.Where(i => !exclusionFilter(i));
|
||||
}
|
||||
return range;
|
||||
}
|
||||
|
||||
internal static IEnumerable<int> GetRange(int min, int max) {
|
||||
return GetRange(min, max, null);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,496 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="Lower.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.Security.AntiXss.CodeCharts {
|
||||
using System.Collections;
|
||||
|
||||
/// <summary>
|
||||
/// Provides safe character positions for the lower section of the UTF code tables.
|
||||
/// </summary>
|
||||
internal static class Lower {
|
||||
/// <summary>
|
||||
/// Determines if the specified flag is set.
|
||||
/// </summary>
|
||||
/// <param name="flags">The value to check.</param>
|
||||
/// <param name="flagToCheck">The flag to check for.</param>
|
||||
/// <returns>true if the flag is set, otherwise false.</returns>
|
||||
public static bool IsFlagSet(LowerCodeCharts flags, LowerCodeCharts flagToCheck) {
|
||||
return (flags & flagToCheck) != 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Basic Latin code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable BasicLatin() {
|
||||
return CodeChartHelper.GetRange(0x0020, 0x007E);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Latin 1 Supplement code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Latin1Supplement() {
|
||||
return CodeChartHelper.GetRange(0x00A1, 0x00FF,
|
||||
i => (i == 0x00AD));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Latin Extended A code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable LatinExtendedA() {
|
||||
return CodeChartHelper.GetRange(0x0100, 0x17F);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Latin Extended B code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable LatinExtendedB() {
|
||||
return CodeChartHelper.GetRange(0x0180, 0x024F);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the IPA Extensions code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable IpaExtensions() {
|
||||
return CodeChartHelper.GetRange(0x0250, 0x2AF);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Spacing Modifiers code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable SpacingModifierLetters() {
|
||||
return CodeChartHelper.GetRange(0x02B0, 0x2FF);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Combining Diacritical Marks code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable CombiningDiacriticalMarks() {
|
||||
return CodeChartHelper.GetRange(0x0300, 0x36F);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Greek and Coptic code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable GreekAndCoptic() {
|
||||
return CodeChartHelper.GetRange(0x0370, 0x03FF,
|
||||
i => (i == 0x378 ||
|
||||
i == 0x379 ||
|
||||
(i >= 0x37F && i <= 0x383) ||
|
||||
i == 0x38B ||
|
||||
i == 0x38D ||
|
||||
i == 0x3A2));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Cyrillic code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Cyrillic() {
|
||||
return CodeChartHelper.GetRange(0x0400, 0x04FF);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Cyrillic Supplement code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable CyrillicSupplement() {
|
||||
return CodeChartHelper.GetRange(0x0500, 0x0525);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Armenian code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Armenian() {
|
||||
return CodeChartHelper.GetRange(0x0531, 0x058A,
|
||||
i => (i == 0x0557 ||
|
||||
i == 0x0558 ||
|
||||
i == 0x0560 ||
|
||||
i == 0x0588));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Hebrew code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Hebrew() {
|
||||
return CodeChartHelper.GetRange(0x0591, 0x05F4,
|
||||
i => ((i >= 0x05C8 && i <= 0x05CF) ||
|
||||
(i >= 0x05EB && i <= 0x05EF)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Arabic code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Arabic() {
|
||||
return CodeChartHelper.GetRange(0x0600, 0x06FF,
|
||||
i => (i == 0x0604 ||
|
||||
i == 0x0605 ||
|
||||
i == 0x061C ||
|
||||
i == 0x061d ||
|
||||
i == 0x0620 ||
|
||||
i == 0x065F));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Syriac code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Syriac() {
|
||||
return CodeChartHelper.GetRange(0x0700, 0x074F,
|
||||
i => (i == 0x070E ||
|
||||
i == 0x074B ||
|
||||
i == 0x074C));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Arabic Supplement code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable ArabicSupplement() {
|
||||
return CodeChartHelper.GetRange(0x0750, 0x077F);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Thaana code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Thaana() {
|
||||
return CodeChartHelper.GetRange(0x0780, 0x07B1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Nko code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Nko() {
|
||||
return CodeChartHelper.GetRange(0x07C0, 0x07FA);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Samaritan code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Samaritan() {
|
||||
return CodeChartHelper.GetRange(0x0800, 0x083E,
|
||||
i => (i == 0x082E ||
|
||||
i == 0x082F));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Devenagari code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Devanagari() {
|
||||
return CodeChartHelper.GetRange(0x0900, 0x097F,
|
||||
i => (i == 0x093A ||
|
||||
i == 0x093B ||
|
||||
i == 0x094F ||
|
||||
i == 0x0956 ||
|
||||
i == 0x0957 ||
|
||||
(i >= 0x0973 && i <= 0x0978)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Bengali code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Bengali() {
|
||||
return CodeChartHelper.GetRange(0x0981, 0x09FB,
|
||||
i => (i == 0x0984 ||
|
||||
i == 0x098D ||
|
||||
i == 0x098E ||
|
||||
i == 0x0991 ||
|
||||
i == 0x0992 ||
|
||||
i == 0x09A9 ||
|
||||
i == 0x09B1 ||
|
||||
i == 0x09B3 ||
|
||||
i == 0x09B4 ||
|
||||
i == 0x09B5 ||
|
||||
i == 0x09BA ||
|
||||
i == 0x09BB ||
|
||||
i == 0x09C5 ||
|
||||
i == 0x09C6 ||
|
||||
i == 0x09C9 ||
|
||||
i == 0x09CA ||
|
||||
(i >= 0x09CF && i <= 0x09D6) ||
|
||||
(i >= 0x09D8 && i <= 0x09DB) ||
|
||||
i == 0x09DE ||
|
||||
i == 0x09E4 ||
|
||||
i == 0x09E5));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Gurmukhi code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Gurmukhi() {
|
||||
return CodeChartHelper.GetRange(0x0A01, 0x0A75,
|
||||
i => (i == 0x0A04 ||
|
||||
(i >= 0x0A0B && i <= 0x0A0E) ||
|
||||
i == 0x0A11 ||
|
||||
i == 0x0A12 ||
|
||||
i == 0x0A29 ||
|
||||
i == 0x0A31 ||
|
||||
i == 0x0A34 ||
|
||||
i == 0x0A37 ||
|
||||
i == 0x0A3A ||
|
||||
i == 0x0A3B ||
|
||||
i == 0x0A3D ||
|
||||
(i >= 0x0A43 && i <= 0x0A46) ||
|
||||
i == 0x0A49 ||
|
||||
i == 0x0A4A ||
|
||||
(i >= 0x0A4E && i <= 0x0A50) ||
|
||||
(i >= 0x0A52 && i <= 0x0A58) ||
|
||||
i == 0x0A5D ||
|
||||
(i >= 0x0A5F && i <= 0x0A65)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Gujarati code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Gujarati() {
|
||||
return CodeChartHelper.GetRange(0x0A81, 0x0AF1,
|
||||
i => (i == 0x0A84 ||
|
||||
i == 0x0A8E ||
|
||||
i == 0x0A92 ||
|
||||
i == 0x0AA9 ||
|
||||
i == 0x0AB1 ||
|
||||
i == 0x0AB4 ||
|
||||
i == 0x0ABA ||
|
||||
i == 0x0ABB ||
|
||||
i == 0x0AC6 ||
|
||||
i == 0x0ACA ||
|
||||
i == 0x0ACE ||
|
||||
i == 0x0ACF ||
|
||||
(i >= 0xAD1 && i <= 0x0ADF) ||
|
||||
i == 0x0AE4 ||
|
||||
i == 0x0AE5 ||
|
||||
i == 0x0AF0));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Oriya code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Oriya() {
|
||||
return CodeChartHelper.GetRange(0x0B01, 0x0B71,
|
||||
i => (i == 0x0B04 ||
|
||||
i == 0x0B0D ||
|
||||
i == 0x0B0E ||
|
||||
i == 0x0B11 ||
|
||||
i == 0x0B12 ||
|
||||
i == 0x0B29 ||
|
||||
i == 0x0B31 ||
|
||||
i == 0x0B34 ||
|
||||
i == 0x0B3A ||
|
||||
i == 0x0B3B ||
|
||||
i == 0x0B45 ||
|
||||
i == 0x0B46 ||
|
||||
i == 0x0B49 ||
|
||||
i == 0x0B4A ||
|
||||
(i >= 0x0B4E && i <= 0x0B55) ||
|
||||
(i >= 0x0B58 && i <= 0x0B5B) ||
|
||||
i == 0x0B5E ||
|
||||
i == 0x0B64 ||
|
||||
i == 0x0B65));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Tamil code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Tamil() {
|
||||
return CodeChartHelper.GetRange(0x0B82, 0x0BFA,
|
||||
i => (i == 0x0B84 ||
|
||||
i == 0x0B8B ||
|
||||
i == 0x0B8C ||
|
||||
i == 0x0B8D ||
|
||||
i == 0x0B91 ||
|
||||
i == 0x0B96 ||
|
||||
i == 0x0B97 ||
|
||||
i == 0x0B98 ||
|
||||
i == 0x0B9B ||
|
||||
i == 0x0B9D ||
|
||||
i == 0x0BA0 ||
|
||||
i == 0x0BA1 ||
|
||||
i == 0x0BA2 ||
|
||||
i == 0x0BA5 ||
|
||||
i == 0x0BA6 ||
|
||||
i == 0x0BA7 ||
|
||||
i == 0x0BAB ||
|
||||
i == 0x0BAC ||
|
||||
i == 0x0BAD ||
|
||||
(i >= 0x0BBA && i <= 0x0BBD) ||
|
||||
i == 0x0BC3 ||
|
||||
i == 0x0BC4 ||
|
||||
i == 0x0BC5 ||
|
||||
i == 0x0BC9 ||
|
||||
i == 0x0BCE ||
|
||||
i == 0x0BCF ||
|
||||
(i >= 0x0BD1 && i <= 0x0BD6) ||
|
||||
(i >= 0x0BD8 && i <= 0x0BE5)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Telugu code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Telugu() {
|
||||
return CodeChartHelper.GetRange(0x0C01, 0x0C7F,
|
||||
i => (i == 0x0C04 ||
|
||||
i == 0x0C0D ||
|
||||
i == 0x0C11 ||
|
||||
i == 0x0C29 ||
|
||||
i == 0x0C34 ||
|
||||
i == 0x0C3A ||
|
||||
i == 0x0C3B ||
|
||||
i == 0x0C3C ||
|
||||
i == 0x0C45 ||
|
||||
i == 0x0C49 ||
|
||||
(i >= 0x0C4E && i <= 0x0C54) ||
|
||||
i == 0x0C57 ||
|
||||
(i >= 0x0C5A && i <= 0x0C5F) ||
|
||||
i == 0x0C64 ||
|
||||
i == 0x0C65 ||
|
||||
(i >= 0x0C70 && i <= 0x0C77)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Kannada code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Kannada() {
|
||||
return CodeChartHelper.GetRange(0x0C82, 0x0CF2,
|
||||
i => (i == 0x0C84 ||
|
||||
i == 0x0C8D ||
|
||||
i == 0x0C91 ||
|
||||
i == 0x0CA9 ||
|
||||
i == 0x0CB4 ||
|
||||
i == 0x0CBA ||
|
||||
i == 0x0CBB ||
|
||||
i == 0x0CC5 ||
|
||||
i == 0x0CC9 ||
|
||||
(i >= 0x0CCE && i <= 0x0CD4) ||
|
||||
(i >= 0x0CD7 && i <= 0x0CDD) ||
|
||||
i == 0x0CDF ||
|
||||
i == 0x0CE4 ||
|
||||
i == 0x0CE5 ||
|
||||
i == 0x0CF0));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Malayalam code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Malayalam() {
|
||||
return CodeChartHelper.GetRange(0x0D02, 0x0D7F,
|
||||
i => (i == 0x0D04 ||
|
||||
i == 0x0D0D ||
|
||||
i == 0x0D11 ||
|
||||
i == 0x0D29 ||
|
||||
i == 0x0D3A ||
|
||||
i == 0x0D3B ||
|
||||
i == 0x0D3C ||
|
||||
i == 0x0D45 ||
|
||||
i == 0x0D49 ||
|
||||
(i >= 0x0D4E && i <= 0x0D56) ||
|
||||
(i >= 0x0D58 && i <= 0x0D5F) ||
|
||||
i == 0x0D64 ||
|
||||
i == 0x0D65 ||
|
||||
i == 0x0D76 ||
|
||||
i == 0x0D77 ||
|
||||
i == 0x0D78));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Sinhala code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Sinhala() {
|
||||
return CodeChartHelper.GetRange(0x0D82, 0x0DF4,
|
||||
i => (i == 0x0D84 ||
|
||||
i == 0x0D97 ||
|
||||
i == 0X0D98 ||
|
||||
i == 0x0D99 ||
|
||||
i == 0x0DB2 ||
|
||||
i == 0x0DBC ||
|
||||
i == 0x0DBE ||
|
||||
i == 0x0DBF ||
|
||||
i == 0x0DC7 ||
|
||||
i == 0x0DC8 ||
|
||||
i == 0x0DC9 ||
|
||||
(i >= 0x0DCB && i <= 0x0DCE) ||
|
||||
i == 0x0DD5 ||
|
||||
i == 0x0DD7 ||
|
||||
(i >= 0x0DE0 && i <= 0x0DF1)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Thai code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Thai() {
|
||||
return CodeChartHelper.GetRange(0x0E01, 0x0E5B,
|
||||
i => (i >= 0x0E3B && i <= 0x0E3E));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Lao code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Lao() {
|
||||
return CodeChartHelper.GetRange(0x0E81, 0x0EDD,
|
||||
i => (i == 0x0E83 ||
|
||||
i == 0x0E85 ||
|
||||
i == 0x0E86 ||
|
||||
i == 0x0E89 ||
|
||||
i == 0x0E8B ||
|
||||
i == 0x0E8C ||
|
||||
(i >= 0x0E8E && i <= 0x0E93) ||
|
||||
i == 0x0E98 ||
|
||||
i == 0x0EA0 ||
|
||||
i == 0x0EA4 ||
|
||||
i == 0x0EA6 ||
|
||||
i == 0x0EA8 ||
|
||||
i == 0x0EA9 ||
|
||||
i == 0x0EAC ||
|
||||
i == 0x0EBA ||
|
||||
i == 0x0EBE ||
|
||||
i == 0x0EBF ||
|
||||
i == 0x0EC5 ||
|
||||
i == 0x0EC7 ||
|
||||
i == 0x0ECE ||
|
||||
i == 0x0ECF ||
|
||||
i == 0x0EDA ||
|
||||
i == 0x0EDB));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Tibetan code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Tibetan() {
|
||||
return CodeChartHelper.GetRange(0x0F00, 0x0FD8,
|
||||
i => (i == 0x0F48 ||
|
||||
(i >= 0x0F6D && i <= 0x0F70) ||
|
||||
(i >= 0x0F8C && i <= 0x0F8F) ||
|
||||
i == 0x0F98 ||
|
||||
i == 0x0FBD ||
|
||||
i == 0x0FCD));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,329 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="LowerMiddle.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.Security.AntiXss.CodeCharts {
|
||||
using System.Collections;
|
||||
|
||||
/// <summary>
|
||||
/// Provides safe character positions for the lower middle section of the UTF code tables.
|
||||
/// </summary>
|
||||
internal static class LowerMiddle {
|
||||
/// <summary>
|
||||
/// Determines if the specified flag is set.
|
||||
/// </summary>
|
||||
/// <param name="flags">The value to check.</param>
|
||||
/// <param name="flagToCheck">The flag to check for.</param>
|
||||
/// <returns>true if the flag is set, otherwise false.</returns>
|
||||
public static bool IsFlagSet(LowerMidCodeCharts flags, LowerMidCodeCharts flagToCheck) {
|
||||
return (flags & flagToCheck) != 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Myanmar code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Myanmar() {
|
||||
return CodeChartHelper.GetRange(0x1000, 0x109F);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Georgian code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Georgian() {
|
||||
return CodeChartHelper.GetRange(0x10A0, 0x10FC,
|
||||
i => (i >= 0x10C6 && i <= 0x10CF));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Hangul Jamo code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable HangulJamo() {
|
||||
return CodeChartHelper.GetRange(0x1100, 0x11FF);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Ethiopic code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Ethiopic() {
|
||||
return CodeChartHelper.GetRange(0x1200, 0x137C,
|
||||
i => (i == 0x1249 ||
|
||||
i == 0x124E ||
|
||||
i == 0x124F ||
|
||||
i == 0x1257 ||
|
||||
i == 0x1259 ||
|
||||
i == 0x125E ||
|
||||
i == 0x125F ||
|
||||
i == 0x1289 ||
|
||||
i == 0x128E ||
|
||||
i == 0x128F ||
|
||||
i == 0x12B1 ||
|
||||
i == 0x12B6 ||
|
||||
i == 0x12B7 ||
|
||||
i == 0x12BF ||
|
||||
i == 0x12C1 ||
|
||||
i == 0x12C6 ||
|
||||
i == 0x12C7 ||
|
||||
i == 0x12D7 ||
|
||||
i == 0x1311 ||
|
||||
i == 0x1316 ||
|
||||
i == 0x1317 ||
|
||||
(i >= 0x135B && i <= 0x135E)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Ethiopic Supplement code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable EthiopicSupplement() {
|
||||
return CodeChartHelper.GetRange(0x1380, 0x1399);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Cherokee code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Cherokee() {
|
||||
return CodeChartHelper.GetRange(0x13A0, 0x13F4);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Unified Canadian Aboriginal Syllabic code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable UnifiedCanadianAboriginalSyllabics() {
|
||||
return CodeChartHelper.GetRange(0x1400, 0x167F);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Ogham code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Ogham() {
|
||||
return CodeChartHelper.GetRange(0x1680, 0x169C);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Runic code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Runic() {
|
||||
return CodeChartHelper.GetRange(0x16A0, 0x16F0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Tagalog code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Tagalog() {
|
||||
return CodeChartHelper.GetRange(0x1700, 0x1714,
|
||||
i => (i == 0x170D));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Hanunoo code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Hanunoo() {
|
||||
return CodeChartHelper.GetRange(0x1720, 0x1736);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Buhid code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Buhid() {
|
||||
return CodeChartHelper.GetRange(0x1740, 0x1753);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Tagbanwa code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Tagbanwa() {
|
||||
return CodeChartHelper.GetRange(0x1760, 0x1773,
|
||||
i => (i == 0x176D ||
|
||||
i == 0x1771));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Khmer code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Khmer() {
|
||||
return CodeChartHelper.GetRange(0x1780, 0x17F9,
|
||||
i => (i == 0x17DE ||
|
||||
i == 0x17DF ||
|
||||
(i >= 0x17EA && i <= 0x17EF)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Mongolian code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Mongolian() {
|
||||
return CodeChartHelper.GetRange(0x1800, 0x18AA,
|
||||
i => (i == 0x180F ||
|
||||
(i >= 0x181A && i <= 0x181F) ||
|
||||
(i >= 0x1878 && i <= 0x187F)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Unified Canadian Aboriginal Syllabic Extended code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable UnifiedCanadianAboriginalSyllabicsExtended() {
|
||||
return CodeChartHelper.GetRange(0x18B0, 0x18F5);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Limbu code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Limbu() {
|
||||
return CodeChartHelper.GetRange(0x1900, 0x194F,
|
||||
i => (i == 0x191D ||
|
||||
i == 0x191E ||
|
||||
i == 0x191F ||
|
||||
(i >= 0x192C && i <= 0x192F) ||
|
||||
(i >= 0x193C && i <= 0x193F) ||
|
||||
i == 0x1941 ||
|
||||
i == 0x1942 ||
|
||||
i == 0x1943));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Tai Le code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable TaiLe() {
|
||||
return CodeChartHelper.GetRange(0x1950, 0x1974,
|
||||
i => (i == 0x196E ||
|
||||
i == 0x196F));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the New Tai Lue code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable NewTaiLue() {
|
||||
return CodeChartHelper.GetRange(0x1980, 0x19DF,
|
||||
i => ((i >= 0x19AC && i <= 0x19AF) ||
|
||||
(i >= 0x19CA && i <= 0x19CF) ||
|
||||
(i >= 0x19DB && i <= 0x19DD)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Khmer Symbols code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable KhmerSymbols() {
|
||||
return CodeChartHelper.GetRange(0x19E0, 0x19FF);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Khmer Symbols code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Buginese() {
|
||||
return CodeChartHelper.GetRange(0x1A00, 0x1A1F,
|
||||
i => (i == 0x1A1C ||
|
||||
i == 0x1A1D));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Tai Tham code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable TaiTham() {
|
||||
return CodeChartHelper.GetRange(0x1A20, 0x1AAD,
|
||||
i => (i == 0x1A5F ||
|
||||
i == 0x1A7D ||
|
||||
i == 0x1A7E ||
|
||||
(i >= 0x1A8A && i <= 0x1A8F) ||
|
||||
(i >= 0x1A9A && i <= 0x1A9F)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Balinese code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Balinese() {
|
||||
return CodeChartHelper.GetRange(0x1B00, 0x1B7C,
|
||||
i => (i >= 0x1B4C && i <= 0x1B4F));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Sudanese code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Sudanese() {
|
||||
return CodeChartHelper.GetRange(0x1B80, 0x1BB9,
|
||||
i => (i >= 0x1BAB && i <= 0x1BAD));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Lepcha code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Lepcha() {
|
||||
return CodeChartHelper.GetRange(0x1C00, 0x1C4F,
|
||||
i => ((i >= 0x1C38 && i <= 0x1C3A) ||
|
||||
(i >= 0x1C4A && i <= 0x1C4C)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Ol Chiki code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable OlChiki() {
|
||||
return CodeChartHelper.GetRange(0x1C50, 0x1C7F);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Vedic Extensions code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable VedicExtensions() {
|
||||
return CodeChartHelper.GetRange(0x1CD0, 0x1CF2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Phonetic Extensions code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable PhoneticExtensions() {
|
||||
return CodeChartHelper.GetRange(0x1D00, 0x1D7F);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Phonetic Extensions Supplement code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable PhoneticExtensionsSupplement() {
|
||||
return CodeChartHelper.GetRange(0x1D80, 0x1DBF);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Combining Diacritical Marks Supplement code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable CombiningDiacriticalMarksSupplement() {
|
||||
return CodeChartHelper.GetRange(0x1DC0, 0x1DFF,
|
||||
i => (i >= 0x1DE7 && i <= 0x1DFC));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Latin Extended Addition code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable LatinExtendedAdditional() {
|
||||
return CodeChartHelper.GetRange(0x1E00, 0x1EFF);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,336 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="Middle.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.Security.AntiXss.CodeCharts {
|
||||
using System.Collections;
|
||||
|
||||
/// <summary>
|
||||
/// Provides safe character positions for the middle section of the UTF code tables.
|
||||
/// </summary>
|
||||
internal static class Middle {
|
||||
/// <summary>
|
||||
/// Determines if the specified flag is set.
|
||||
/// </summary>
|
||||
/// <param name="flags">The value to check.</param>
|
||||
/// <param name="flagToCheck">The flag to check for.</param>
|
||||
/// <returns>true if the flag is set, otherwise false.</returns>
|
||||
public static bool IsFlagSet(MidCodeCharts flags, MidCodeCharts flagToCheck) {
|
||||
return (flags & flagToCheck) != 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Greek Extended code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable GreekExtended() {
|
||||
|
||||
return CodeChartHelper.GetRange(0x1F00, 0x1FFE,
|
||||
i => (i == 0x1F16 ||
|
||||
i == 0x1F17 ||
|
||||
i == 0x1F1E ||
|
||||
i == 0x1F1F ||
|
||||
i == 0x1F46 ||
|
||||
i == 0x1F47 ||
|
||||
i == 0x1F4E ||
|
||||
i == 0x1F4F ||
|
||||
i == 0x1F58 ||
|
||||
i == 0x1F5A ||
|
||||
i == 0x1F5C ||
|
||||
i == 0x1F5E ||
|
||||
i == 0x1F7E ||
|
||||
i == 0x1F7F ||
|
||||
i == 0x1FB5 ||
|
||||
i == 0x1FC5 ||
|
||||
i == 0x1FD4 ||
|
||||
i == 0x1FD5 ||
|
||||
i == 0x1FDC ||
|
||||
i == 0x1FF0 ||
|
||||
i == 0x1FF1 ||
|
||||
i == 0x1FF5));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the General Punctuation code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable GeneralPunctuation() {
|
||||
return CodeChartHelper.GetRange(0x2000, 0x206F,
|
||||
i => (i >= 0x2065 && i <= 0x2069));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Superscripts and subscripts code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable SuperscriptsAndSubscripts() {
|
||||
return CodeChartHelper.GetRange(0x2070, 0x2094,
|
||||
i => (i == 0x2072 ||
|
||||
i == 0x2073 ||
|
||||
i == 0x208F));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Currency Symbols code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable CurrencySymbols() {
|
||||
return CodeChartHelper.GetRange(0x20A0, 0x20B8);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Combining Diacritrical Marks for Symbols code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable CombiningDiacriticalMarksForSymbols() {
|
||||
return CodeChartHelper.GetRange(0x20D0, 0x20F0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Letterlike Symbols code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable LetterlikeSymbols() {
|
||||
return CodeChartHelper.GetRange(0x2100, 0x214F);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Number Forms code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable NumberForms() {
|
||||
return CodeChartHelper.GetRange(0x2150, 0x2189);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Arrows code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Arrows() {
|
||||
return CodeChartHelper.GetRange(0x2190, 0x21FF);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Mathematical Operators code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable MathematicalOperators() {
|
||||
return CodeChartHelper.GetRange(0x2200, 0x22FF);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Miscellaneous Technical code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable MiscellaneousTechnical() {
|
||||
return CodeChartHelper.GetRange(0x2300, 0x23E8);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Control Pictures code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable ControlPictures() {
|
||||
return CodeChartHelper.GetRange(0x2400, 0x2426);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the OCR code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable OpticalCharacterRecognition() {
|
||||
return CodeChartHelper.GetRange(0x2440, 0x244A);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Enclosed Alphanumerics code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable EnclosedAlphanumerics() {
|
||||
return CodeChartHelper.GetRange(0x2460, 0x24FF);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Box Drawing code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable BoxDrawing() {
|
||||
return CodeChartHelper.GetRange(0x2500, 0x257F);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Block Elements code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable BlockElements() {
|
||||
return CodeChartHelper.GetRange(0x2580, 0x259F);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Geometric Shapes code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable GeometricShapes() {
|
||||
return CodeChartHelper.GetRange(0x25A0, 0x25FF);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Miscellaneous Symbols code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable MiscellaneousSymbols() {
|
||||
return CodeChartHelper.GetRange(0x2600, 0x26FF,
|
||||
i => (i == 0x26CE ||
|
||||
i == 0x26E2 ||
|
||||
(i >= 0x26E4 && i <= 0x26E7)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Dingbats code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Dingbats() {
|
||||
return CodeChartHelper.GetRange(0x2701, 0x27BE,
|
||||
i => (i == 0x2705 ||
|
||||
i == 0x270A ||
|
||||
i == 0x270B ||
|
||||
i == 0x2728 ||
|
||||
i == 0x274C ||
|
||||
i == 0x274E ||
|
||||
i == 0x2753 ||
|
||||
i == 0x2754 ||
|
||||
i == 0x2755 ||
|
||||
i == 0x275F ||
|
||||
i == 0x2760 ||
|
||||
i == 0x2795 ||
|
||||
i == 0x2796 ||
|
||||
i == 0x2797 ||
|
||||
i == 0x27B0));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Miscellaneous Mathematical Symbols A code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable MiscellaneousMathematicalSymbolsA() {
|
||||
return CodeChartHelper.GetRange(0x27C0, 0x27EF,
|
||||
i => (i == 0x27CB ||
|
||||
i == 0x27CD ||
|
||||
i == 0x27CE ||
|
||||
i == 0x27CF));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Supplemental Arrows A code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable SupplementalArrowsA() {
|
||||
return CodeChartHelper.GetRange(0x27F0, 0x27FF);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Braille Patterns code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable BraillePatterns() {
|
||||
return CodeChartHelper.GetRange(0x2800, 0x28FF);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Supplemental Arrows B code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable SupplementalArrowsB() {
|
||||
return CodeChartHelper.GetRange(0x2900, 0x297F);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Miscellaneous Mathematical Symbols B code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable MiscellaneousMathematicalSymbolsB() {
|
||||
return CodeChartHelper.GetRange(0x2980, 0x29FF);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Supplemental Mathematical Operators code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable SupplementalMathematicalOperators() {
|
||||
return CodeChartHelper.GetRange(0x2A00, 0x2AFF);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Miscellaneous Symbols and Arrows code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable MiscellaneousSymbolsAndArrows() {
|
||||
return CodeChartHelper.GetRange(0x2B00, 0x2B59,
|
||||
i => (i == 0x2B4D ||
|
||||
i == 0x2B4E ||
|
||||
i == 0x2B4F));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Glagolitic code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Glagolitic() {
|
||||
return CodeChartHelper.GetRange(0x2C00, 0x2C5E,
|
||||
i => (i == 0x2C2F));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Latin Extended C code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable LatinExtendedC() {
|
||||
return CodeChartHelper.GetRange(0x2C60, 0x2C7F);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Coptic table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Coptic() {
|
||||
return CodeChartHelper.GetRange(0x2C80, 0x2CFF,
|
||||
i => (i >= 0x2CF2 && i <= 0x2CF8));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Georgian Supplement code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable GeorgianSupplement() {
|
||||
return CodeChartHelper.GetRange(0x2D00, 0x2D25);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Tifinagh code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Tifinagh() {
|
||||
return CodeChartHelper.GetRange(0x2D30, 0x2D6F,
|
||||
i => (i >= 0x2D66 && i <= 0x2D6E));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Ethiopic Extended code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable EthiopicExtended() {
|
||||
return CodeChartHelper.GetRange(0x2D80, 0x2DDE,
|
||||
i => ((i >= 0x2D97 && i <= 0x2D9F) ||
|
||||
i == 0x2DA7 ||
|
||||
i == 0x2DAF ||
|
||||
i == 0x2DB7 ||
|
||||
i == 0x2DBF ||
|
||||
i == 0x2DC7 ||
|
||||
i == 0x2DCF ||
|
||||
i == 0x2DD7 ||
|
||||
i == 0x2DDF));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,247 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="Upper.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.Security.AntiXss.CodeCharts {
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
|
||||
/// <summary>
|
||||
/// Provides safe character positions for the upper section of the UTF code tables.
|
||||
/// </summary>
|
||||
internal static class Upper {
|
||||
/// <summary>
|
||||
/// Determines if the specified flag is set.
|
||||
/// </summary>
|
||||
/// <param name="flags">The value to check.</param>
|
||||
/// <param name="flagToCheck">The flag to check for.</param>
|
||||
/// <returns>true if the flag is set, otherwise false.</returns>
|
||||
public static bool IsFlagSet(UpperCodeCharts flags, UpperCodeCharts flagToCheck) {
|
||||
return (flags & flagToCheck) != 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Devanagari Extended code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable DevanagariExtended() {
|
||||
return CodeChartHelper.GetRange(0xA8E0, 0xA8FB);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Kayah Li code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable KayahLi() {
|
||||
return CodeChartHelper.GetRange(0xA900, 0xA92F);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Rejang code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Rejang() {
|
||||
return CodeChartHelper.GetRange(0xA930, 0xA953).Concat(
|
||||
new[] { 0xA95F });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Hangul Jamo Extended A code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable HangulJamoExtendedA() {
|
||||
return CodeChartHelper.GetRange(0xA960, 0xA97C);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Javanese code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Javanese() {
|
||||
return CodeChartHelper.GetRange(0xA980, 0xA9DF,
|
||||
i => (i == 0xA9CE ||
|
||||
(i >= 0xA9DA && i <= 0xA9DD)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Cham code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Cham() {
|
||||
return CodeChartHelper.GetRange(0xAA00, 0xAA5F,
|
||||
i => ((i >= 0xAA37 && i <= 0xAA3F) ||
|
||||
i == 0xAA4E ||
|
||||
i == 0xAA4F ||
|
||||
i == 0xAA5A ||
|
||||
i == 0xAA5B));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Myanmar Extended A code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable MyanmarExtendedA() {
|
||||
return CodeChartHelper.GetRange(0xAA60, 0xAA7B);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Myanmar Extended A code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable TaiViet() {
|
||||
return CodeChartHelper.GetRange(0xAA80, 0xAAC2).Concat(
|
||||
CodeChartHelper.GetRange(0xAADB, 0xAADF));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Meetei Mayek code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable MeeteiMayek() {
|
||||
return CodeChartHelper.GetRange(0xABC0, 0xABF9,
|
||||
i => (i == 0xABEE ||
|
||||
i == 0xABEF));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Hangul Syllables code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable HangulSyllables() {
|
||||
return CodeChartHelper.GetRange(0xAC00, 0xD7A3);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Hangul Jamo Extended B code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable HangulJamoExtendedB() {
|
||||
return CodeChartHelper.GetRange(0xD7B0, 0xD7FB,
|
||||
i => (i == 0xD7C7 ||
|
||||
i == 0xD7C8 ||
|
||||
i == 0xD7C9 ||
|
||||
i == 0xD7CA));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the CJK Compatibility Ideographs code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable CjkCompatibilityIdeographs() {
|
||||
return CodeChartHelper.GetRange(0xF900, 0xFAD9,
|
||||
i => (i == 0xFA2E ||
|
||||
i == 0xFA2F ||
|
||||
i == 0xFA6E ||
|
||||
i == 0xFA6F));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Alphabetic Presentation Forms code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable AlphabeticPresentationForms() {
|
||||
return CodeChartHelper.GetRange(0xFB00, 0xFB4F,
|
||||
i => ((i >= 0xFB07 && i <= 0xFB12) ||
|
||||
(i >= 0xFB18 && i <= 0xFB1C) ||
|
||||
i == 0xFB37 ||
|
||||
i == 0xFB3D ||
|
||||
i == 0xFB3F ||
|
||||
i == 0xFB42 ||
|
||||
i == 0xFB45));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Arabic Presentation Forms A code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable ArabicPresentationFormsA() {
|
||||
return CodeChartHelper.GetRange(0xFB50, 0xFDFD,
|
||||
i => ((i >= 0xFBB2 && i <= 0xFBD2) ||
|
||||
(i >= 0xFD40 && i <= 0xFD4F) ||
|
||||
i == 0xFD90 ||
|
||||
i == 0xFD91 ||
|
||||
(i >= 0xFDC8 && i <= 0xFDEF)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Variation Selectors code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable VariationSelectors() {
|
||||
return CodeChartHelper.GetRange(0xFE00, 0xFE0F);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Vertical Forms code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable VerticalForms() {
|
||||
return CodeChartHelper.GetRange(0xFE10, 0xFE19);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Combining Half Marks code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable CombiningHalfMarks() {
|
||||
return CodeChartHelper.GetRange(0xFE20, 0xFE26);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the CJK Compatibility Forms code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable CjkCompatibilityForms() {
|
||||
return CodeChartHelper.GetRange(0xFE30, 0xFE4F);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Small Form Variants code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable SmallFormVariants() {
|
||||
return CodeChartHelper.GetRange(0xFE50, 0xFE6B,
|
||||
i => (i == 0xFE53 || i == 0xFE67));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Arabic Presentation Forms B code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable ArabicPresentationFormsB() {
|
||||
return CodeChartHelper.GetRange(0xFE70, 0xFEFC,
|
||||
i => (i == 0xFE75));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Half Width and Full Width Forms code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable HalfWidthAndFullWidthForms() {
|
||||
return CodeChartHelper.GetRange(0xFF01, 0xFFEE,
|
||||
i => (i == 0xFFBF ||
|
||||
i == 0xFFC0 ||
|
||||
i == 0xFFC1 ||
|
||||
i == 0xFFC8 ||
|
||||
i == 0xFFC9 ||
|
||||
i == 0xFFD0 ||
|
||||
i == 0xFFD1 ||
|
||||
i == 0xFFD8 ||
|
||||
i == 0xFFD9 ||
|
||||
i == 0xFFDD ||
|
||||
i == 0xFFDE ||
|
||||
i == 0xFFDF ||
|
||||
i == 0xFFE7));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Specials code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Specials() {
|
||||
return CodeChartHelper.GetRange(0xFFF9, 0xFFFD);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,282 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="UpperMiddle.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.Security.AntiXss.CodeCharts {
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
|
||||
/// <summary>
|
||||
/// Provides safe character positions for the upper middle section of the UTF code tables.
|
||||
/// </summary>
|
||||
internal static class UpperMiddle {
|
||||
/// <summary>
|
||||
/// Determines if the specified flag is set.
|
||||
/// </summary>
|
||||
/// <param name="flags">The value to check.</param>
|
||||
/// <param name="flagToCheck">The flag to check for.</param>
|
||||
/// <returns>true if the flag is set, otherwise false.</returns>
|
||||
public static bool IsFlagSet(UpperMidCodeCharts flags, UpperMidCodeCharts flagToCheck) {
|
||||
return (flags & flagToCheck) != 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Cyrillic Extended A code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable CyrillicExtendedA() {
|
||||
return CodeChartHelper.GetRange(0x2DE0, 0x2DFF);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Cyrillic Extended A code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable SupplementalPunctuation() {
|
||||
return CodeChartHelper.GetRange(0x2E00, 0x2E31);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the CJK Radicals Supplement code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable CjkRadicalsSupplement() {
|
||||
return CodeChartHelper.GetRange(0x2E80, 0x2EF3,
|
||||
i => (i == 0x2E9A));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Kangxi Radicals code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable KangxiRadicals() {
|
||||
return CodeChartHelper.GetRange(0x2F00, 0x2FD5);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Ideographic Description Characters code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable IdeographicDescriptionCharacters() {
|
||||
return CodeChartHelper.GetRange(0x2FF0, 0x2FFB);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the CJK Symbols and Punctuation code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable CjkSymbolsAndPunctuation() {
|
||||
return CodeChartHelper.GetRange(0x3000, 0x303F);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Hiragana code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Hiragana() {
|
||||
return CodeChartHelper.GetRange(0x3041, 0x309F,
|
||||
i => (i == 0x3097 ||
|
||||
i == 0x3098));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Hiragana code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Katakana() {
|
||||
return CodeChartHelper.GetRange(0x30A0, 0x30FF);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Bopomofo code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Bopomofo() {
|
||||
return CodeChartHelper.GetRange(0x3105, 0x312D);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Hangul Compatibility Jamo code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable HangulCompatibilityJamo() {
|
||||
return CodeChartHelper.GetRange(0x3131, 0x318E);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Kanbun code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Kanbun() {
|
||||
return CodeChartHelper.GetRange(0x3190, 0x319F);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Bopomofo Extended code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable BopomofoExtended() {
|
||||
return CodeChartHelper.GetRange(0x31A0, 0x31B7);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the CJK Strokes code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable CjkStrokes() {
|
||||
return CodeChartHelper.GetRange(0x31C0, 0x31E3);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Katakana Phonetic Extensions code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable KatakanaPhoneticExtensions() {
|
||||
return CodeChartHelper.GetRange(0x31F0, 0x31FF);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Enclosed CJK Letters and Months code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable EnclosedCjkLettersAndMonths() {
|
||||
return CodeChartHelper.GetRange(0x3200, 0x32FE,
|
||||
i => (i == 0x321F));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the CJK Compatibility code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable CjkCompatibility() {
|
||||
return CodeChartHelper.GetRange(0x3300, 0x33FF);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the CJK Unified Ideographs Extension A code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable CjkUnifiedIdeographsExtensionA() {
|
||||
return CodeChartHelper.GetRange(0x3400, 0x4DB5);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Yijing Hexagram Symbols code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable YijingHexagramSymbols() {
|
||||
return CodeChartHelper.GetRange(0x4DC0, 0x4DFF);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the CJK Unified Ideographs code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable CjkUnifiedIdeographs() {
|
||||
return CodeChartHelper.GetRange(0x4E00, 0x9FCB);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Yi Syllables code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable YiSyllables() {
|
||||
return CodeChartHelper.GetRange(0xA000, 0xA48C);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Yi Radicals code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable YiRadicals() {
|
||||
return CodeChartHelper.GetRange(0xA490, 0xA4C6);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Lisu code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Lisu() {
|
||||
return CodeChartHelper.GetRange(0xA4D0, 0xA4FF);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Vai code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Vai() {
|
||||
return CodeChartHelper.GetRange(0xA500, 0xA62B);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Cyrillic Extended B code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable CyrillicExtendedB() {
|
||||
return CodeChartHelper.GetRange(0xA640, 0xA697,
|
||||
i => (i == 0xA660 ||
|
||||
i == 0xA661 ||
|
||||
(i >= 0xA674 && i <= 0xA67b)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Bamum code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Bamum() {
|
||||
return CodeChartHelper.GetRange(0xA6A0, 0xA6F7);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Modifier Tone Letters code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable ModifierToneLetters() {
|
||||
return CodeChartHelper.GetRange(0xA700, 0xA71F);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Latin Extended D code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable LatinExtendedD() {
|
||||
return CodeChartHelper.GetRange(0xA720, 0xA78C).Concat(
|
||||
CodeChartHelper.GetRange(0xA7FB, 0xA7FF));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Syloti Nagri code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable SylotiNagri() {
|
||||
return CodeChartHelper.GetRange(0xA800, 0xA82B);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Common Indic Number Forms code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable CommonIndicNumberForms() {
|
||||
return CodeChartHelper.GetRange(0xA830, 0xA839);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Phags-pa code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Phagspa() {
|
||||
return CodeChartHelper.GetRange(0xA840, 0xA877);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for the Saurashtra code table.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for the code table.</returns>
|
||||
public static IEnumerable Saurashtra() {
|
||||
return CodeChartHelper.GetRange(0xA880, 0xA8D9,
|
||||
i => (i >= 0xA8C5 && i <= 0xA8CD));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,97 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="CssEncoder.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.Security.AntiXss {
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
/// <summary>
|
||||
/// Provides CSS Encoding methods.
|
||||
/// </summary>
|
||||
internal static class CssEncoder {
|
||||
|
||||
/// <summary>
|
||||
/// The values to output for each character.
|
||||
/// </summary>
|
||||
private static Lazy<char[][]> characterValuesLazy = new Lazy<char[][]>(InitialiseSafeList);
|
||||
|
||||
/// <summary>
|
||||
/// Encodes according to the CSS encoding rules.
|
||||
/// </summary>
|
||||
/// <param name="input">The string to encode.</param>
|
||||
/// <returns>The encoded string.</returns>
|
||||
internal static string Encode(string input) {
|
||||
if (string.IsNullOrEmpty(input)) {
|
||||
return input;
|
||||
}
|
||||
|
||||
char[][] characterValues = characterValuesLazy.Value;
|
||||
|
||||
// Setup a new StringBuilder for output.
|
||||
// Worse case scenario - CSS encoding wants \XXXXXX for encoded characters.
|
||||
StringBuilder builder = EncoderUtil.GetOutputStringBuilder(input.Length, 7 /* worstCaseOutputCharsPerInputChar */);
|
||||
|
||||
Utf16StringReader stringReader = new Utf16StringReader(input);
|
||||
while (true) {
|
||||
int currentCodePoint = stringReader.ReadNextScalarValue();
|
||||
if (currentCodePoint < 0) {
|
||||
break; // EOF
|
||||
}
|
||||
|
||||
if (currentCodePoint >= characterValues.Length) {
|
||||
// We don't have a pre-generated mapping of characters beyond the U+00FF, so we need
|
||||
// to generate these encodings on-the-fly. We should encode the code point rather
|
||||
// than the surrogate code units that make up this code point.
|
||||
// See: http://www.w3.org/International/questions/qa-escapes#cssescapes
|
||||
|
||||
char[] encodedCharacter = SafeList.SlashThenSixDigitHexValueGenerator(currentCodePoint);
|
||||
builder.Append(encodedCharacter);
|
||||
}
|
||||
else if (characterValues[currentCodePoint] != null) {
|
||||
// character needs to be encoded
|
||||
char[] encodedCharacter = characterValues[currentCodePoint];
|
||||
builder.Append(encodedCharacter);
|
||||
}
|
||||
else {
|
||||
// character does not need encoding
|
||||
builder.Append((char)currentCodePoint);
|
||||
}
|
||||
}
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the HTML safe list.
|
||||
/// </summary>
|
||||
private static char[][] InitialiseSafeList() {
|
||||
char[][] result = SafeList.Generate(0xFF, SafeList.SlashThenSixDigitHexValueGenerator);
|
||||
SafeList.PunchSafeList(ref result, CssSafeList());
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for CS encoding.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for CSS encoding.</returns>
|
||||
/// <remarks>See http://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet </remarks>
|
||||
private static IEnumerable CssSafeList() {
|
||||
for (int i = '0'; i <= '9'; i++) {
|
||||
yield return i;
|
||||
}
|
||||
|
||||
for (int i = 'A'; i <= 'Z'; i++) {
|
||||
yield return i;
|
||||
}
|
||||
|
||||
for (int i = 'a'; i <= 'z'; i++) {
|
||||
yield return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,47 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="EncoderUtil.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.Security.AntiXss {
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
/// <summary>
|
||||
/// Provides helper methods common to all Anti-XSS encoders.
|
||||
/// </summary>
|
||||
internal static class EncoderUtil {
|
||||
|
||||
/// <summary>
|
||||
/// Gets an appropriately-sized StringBuilder for the output of an encoding routine.
|
||||
/// </summary>
|
||||
/// <param name="inputLength">The length (in characters) of the input string.</param>
|
||||
/// <param name="worstCaseOutputCharsPerInputChar">The worst-case ratio of output characters per input character.</param>
|
||||
/// <returns>A StringBuilder appropriately-sized to hold the output string.</returns>
|
||||
internal static StringBuilder GetOutputStringBuilder(int inputLength, int worstCaseOutputCharsPerInputChar) {
|
||||
// We treat 32KB byte size (16k chars) as a soft upper boundary for the length of any StringBuilder
|
||||
// that we allocate. We'll try to avoid going above this boundary if we can avoid it so that we
|
||||
// don't allocate objects on the LOH.
|
||||
const int upperBound = 16 * 1024;
|
||||
|
||||
int charsToAllocate;
|
||||
if (inputLength >= upperBound) {
|
||||
// We know that the output will contain at least as many characters as the input, so if the
|
||||
// input length exceeds the soft upper boundary just preallocate the entire builder and hope for
|
||||
// a best-case outcome.
|
||||
charsToAllocate = inputLength;
|
||||
}
|
||||
else {
|
||||
// Allocate the worst-case if we can, but don't exceed the soft upper boundary.
|
||||
long worstCaseTotalChars = (long)inputLength * worstCaseOutputCharsPerInputChar; // don't overflow Int32
|
||||
charsToAllocate = (int)Math.Min(upperBound, worstCaseTotalChars);
|
||||
}
|
||||
|
||||
// Once we have chosen an initial value for the StringBuilder size, the StringBuilder type will
|
||||
// efficiently allocate additionally blocks if necessary.
|
||||
return new StringBuilder(charsToAllocate);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,58 @@
|
||||
// AntiXSS global suppressions
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Alphanumerics", Scope = "member", Target = "System.Web.Security.AntiXss.MidCodeCharts.#EnclosedAlphanumerics", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Bamum", Scope = "member", Target = "System.Web.Security.AntiXss.UpperMidCodeCharts.#Bamum", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Buginese", Scope = "member", Target = "System.Web.Security.AntiXss.LowerMidCodeCharts.#Buginese", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Buhid", Scope = "member", Target = "System.Web.Security.AntiXss.LowerMidCodeCharts.#Buhid", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Chiki", Scope = "member", Target = "System.Web.Security.AntiXss.LowerMidCodeCharts.#OlChiki", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Cjk", Scope = "member", Target = "System.Web.Security.AntiXss.UpperCodeCharts.#CjkCompatibilityForms", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Cjk", Scope = "member", Target = "System.Web.Security.AntiXss.UpperMidCodeCharts.#EnclosedCjkLettersAndMonths", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Cjk", Scope = "member", Target = "System.Web.Security.AntiXss.UpperMidCodeCharts.#CjkUnifiedIdeographsExtensionA", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Cjk", Scope = "member", Target = "System.Web.Security.AntiXss.UpperMidCodeCharts.#CjkUnifiedIdeographs", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Cjk", Scope = "member", Target = "System.Web.Security.AntiXss.UpperMidCodeCharts.#CjkSymbolsAndPunctuation", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Cjk", Scope = "member", Target = "System.Web.Security.AntiXss.UpperMidCodeCharts.#CjkStrokes", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Cjk", Scope = "member", Target = "System.Web.Security.AntiXss.UpperMidCodeCharts.#CjkRadicalsSupplement", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Cjk", Scope = "member", Target = "System.Web.Security.AntiXss.UpperMidCodeCharts.#CjkCompatibility", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Cjk", Scope = "member", Target = "System.Web.Security.AntiXss.UpperCodeCharts.#CjkCompatibilityIdeographs", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Devanagari", Scope = "member", Target = "System.Web.Security.AntiXss.UpperCodeCharts.#DevanagariExtended", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Devanagari", Scope = "member", Target = "System.Web.Security.AntiXss.LowerCodeCharts.#Devanagari", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Glagolitic", Scope = "member", Target = "System.Web.Security.AntiXss.MidCodeCharts.#Glagolitic", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gurmukhi", Scope = "member", Target = "System.Web.Security.AntiXss.LowerCodeCharts.#Gurmukhi", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Hanunoo", Scope = "member", Target = "System.Web.Security.AntiXss.LowerMidCodeCharts.#Hanunoo", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Jamo", Scope = "member", Target = "System.Web.Security.AntiXss.UpperCodeCharts.#HangulJamoExtendedA", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Jamo", Scope = "member", Target = "System.Web.Security.AntiXss.UpperMidCodeCharts.#HangulCompatibilityJamo", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Jamo", Scope = "member", Target = "System.Web.Security.AntiXss.UpperCodeCharts.#HangulJamoExtendedB", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Jamo", Scope = "member", Target = "System.Web.Security.AntiXss.LowerMidCodeCharts.#HangulJamo", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Kanbun", Scope = "member", Target = "System.Web.Security.AntiXss.UpperMidCodeCharts.#Kanbun", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Kangxi", Scope = "member", Target = "System.Web.Security.AntiXss.UpperMidCodeCharts.#KangxiRadicals", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Kayah", Scope = "member", Target = "System.Web.Security.AntiXss.UpperCodeCharts.#KayahLi", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Lepcha", Scope = "member", Target = "System.Web.Security.AntiXss.LowerMidCodeCharts.#Lepcha", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Letterlike", Scope = "member", Target = "System.Web.Security.AntiXss.MidCodeCharts.#LetterlikeSymbols", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Limbu", Scope = "member", Target = "System.Web.Security.AntiXss.LowerMidCodeCharts.#Limbu", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Lisu", Scope = "member", Target = "System.Web.Security.AntiXss.UpperMidCodeCharts.#Lisu", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Lue", Scope = "member", Target = "System.Web.Security.AntiXss.LowerMidCodeCharts.#NewTaiLue", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Mayek", Scope = "member", Target = "System.Web.Security.AntiXss.UpperCodeCharts.#MeeteiMayek", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Meetei", Scope = "member", Target = "System.Web.Security.AntiXss.UpperCodeCharts.#MeeteiMayek", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Nagri", Scope = "member", Target = "System.Web.Security.AntiXss.UpperMidCodeCharts.#SylotiNagri", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Nko", Scope = "member", Target = "System.Web.Security.AntiXss.LowerCodeCharts.#Nko", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Ogham", Scope = "member", Target = "System.Web.Security.AntiXss.LowerMidCodeCharts.#Ogham", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Ol", Scope = "member", Target = "System.Web.Security.AntiXss.LowerMidCodeCharts.#OlChiki", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Phagspa", Scope = "member", Target = "System.Web.Security.AntiXss.UpperMidCodeCharts.#Phagspa", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Rejang", Scope = "member", Target = "System.Web.Security.AntiXss.UpperCodeCharts.#Rejang", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Saurashtra", Scope = "member", Target = "System.Web.Security.AntiXss.UpperMidCodeCharts.#Saurashtra", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Syloti", Scope = "member", Target = "System.Web.Security.AntiXss.UpperMidCodeCharts.#SylotiNagri", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Syriac", Scope = "member", Target = "System.Web.Security.AntiXss.LowerCodeCharts.#Syriac", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Tagalog", Scope = "member", Target = "System.Web.Security.AntiXss.LowerMidCodeCharts.#Tagalog", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Tagbanwa", Scope = "member", Target = "System.Web.Security.AntiXss.LowerMidCodeCharts.#Tagbanwa", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Tham", Scope = "member", Target = "System.Web.Security.AntiXss.LowerMidCodeCharts.#TaiTham", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Tifinagh", Scope = "member", Target = "System.Web.Security.AntiXss.MidCodeCharts.#Tifinagh", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Vai", Scope = "member", Target = "System.Web.Security.AntiXss.UpperMidCodeCharts.#Vai", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Xss", Scope = "type", Target = "System.Web.Security.AntiXss.AntiXssEncoder", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Yijing", Scope = "member", Target = "System.Web.Security.AntiXss.UpperMidCodeCharts.#YijingHexagramSymbols", Justification = "AntiXSS baseline.")]
|
||||
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Le", Scope = "member", Target = "System.Web.Security.AntiXss.LowerMidCodeCharts.#TaiLe", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Ol", Scope = "member", Target = "System.Web.Security.AntiXss.LowerMidCodeCharts.#OlChiki", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Li", Scope = "member", Target = "System.Web.Security.AntiXss.UpperCodeCharts.#KayahLi", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Yi", Scope = "member", Target = "System.Web.Security.AntiXss.UpperMidCodeCharts.#YiSyllables", Justification = "AntiXSS baseline.")]
|
||||
[module: SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Yi", Scope = "member", Target = "System.Web.Security.AntiXss.UpperMidCodeCharts.#YiRadicals", Justification = "AntiXSS baseline.")]
|
@@ -0,0 +1,239 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="HtmlParameterEncoder.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.Security.AntiXss {
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
/// <summary>
|
||||
/// The type of space encoding to use.
|
||||
/// </summary>
|
||||
internal enum EncodingType {
|
||||
/// <summary>
|
||||
/// Encode spaces for use in query strings
|
||||
/// </summary>
|
||||
QueryString = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Encode spaces for use in form data
|
||||
/// </summary>
|
||||
HtmlForm = 2
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides Html Parameter Encoding methods.
|
||||
/// </summary>
|
||||
internal static class HtmlParameterEncoder {
|
||||
|
||||
/// <summary>
|
||||
/// The value to use when encoding a space for query strings.
|
||||
/// </summary>
|
||||
private static readonly char[] QueryStringSpace = "%20".ToCharArray();
|
||||
|
||||
/// <summary>
|
||||
/// The value to use when encoding a space for form data.
|
||||
/// </summary>
|
||||
private static readonly char[] FormStringSpace = "+".ToCharArray();
|
||||
|
||||
/// <summary>
|
||||
/// The values to output for each character.
|
||||
/// </summary>
|
||||
private static Lazy<char[][]> characterValuesLazy = new Lazy<char[][]>(InitialiseSafeList);
|
||||
|
||||
/// <summary>
|
||||
/// Encodes a string for query string encoding and returns the encoded string.
|
||||
/// </summary>
|
||||
/// <param name="s">The text to URL-encode.</param>
|
||||
/// <param name="encoding">The encoding for the text parameter.</param>
|
||||
/// <returns>The URL-encoded text.</returns>
|
||||
/// <remarks>URL encoding ensures that all browsers will correctly transmit text in URL strings.
|
||||
/// Characters such as a question mark (?), ampersand (&), slash mark (/), and spaces might be truncated or corrupted by some browsers.
|
||||
/// As a result, these characters must be encoded in <a> tags or in query strings where the strings can be re-sent by a browser
|
||||
/// in a request string.</remarks>
|
||||
/// <exception cref="ArgumentNullException">Thrown if the encoding is null.</exception>
|
||||
internal static string QueryStringParameterEncode(string s, Encoding encoding) {
|
||||
return FormQueryEncode(s, encoding, EncodingType.QueryString);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encodes a string for form URL encoding and returns the encoded string.
|
||||
/// </summary>
|
||||
/// <param name="s">The text to URL-encode.</param>
|
||||
/// <param name="encoding">The encoding for the text parameter.</param>
|
||||
/// <returns>The URL-encoded text.</returns>
|
||||
/// <remarks>URL encoding ensures that all browsers will correctly transmit text in URL strings.
|
||||
/// Characters such as a question mark (?), ampersand (&), slash mark (/), and spaces might be truncated or corrupted by some browsers.
|
||||
/// As a result, these characters must be encoded in <a> tags or in query strings where the strings can be re-sent by a browser
|
||||
/// in a request string.</remarks>
|
||||
/// <exception cref="ArgumentNullException">Thrown if the encoding is null.</exception>
|
||||
internal static string FormStringParameterEncode(string s, Encoding encoding) {
|
||||
return FormQueryEncode(s, encoding, EncodingType.HtmlForm);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encodes a string for Query String or Form Data encoding.
|
||||
/// </summary>
|
||||
/// <param name="s">The text to URL-encode.</param>
|
||||
/// <param name="encoding">The encoding for the text parameter.</param>
|
||||
/// <param name="encodingType">The encoding type to use.</param>
|
||||
/// <returns>The encoded text.</returns>
|
||||
private static string FormQueryEncode(string s, Encoding encoding, EncodingType encodingType) {
|
||||
return FormQueryEncode(s, encoding, encodingType, characterValuesLazy);
|
||||
}
|
||||
|
||||
private static string FormQueryEncode(string s, Encoding encoding, EncodingType encodingType, Lazy<char[][]> characterValuesLazy) {
|
||||
if (string.IsNullOrEmpty(s)) {
|
||||
return s;
|
||||
}
|
||||
|
||||
if (encoding == null) {
|
||||
throw new ArgumentNullException("encoding");
|
||||
}
|
||||
|
||||
var characterValues = characterValuesLazy.Value;
|
||||
|
||||
// RFC 3986 states strings must be converted to their UTF8 value before URL encoding.
|
||||
// See http://tools.ietf.org/html/rfc3986
|
||||
// Conversion to char[] keeps null characters inline.
|
||||
byte[] utf8Bytes = encoding.GetBytes(s.ToCharArray());
|
||||
char[] encodedInput = new char[utf8Bytes.Length * 3]; // Each byte can potentially be encoded as %xx
|
||||
int outputLength = 0;
|
||||
|
||||
for (int characterPosition = 0; characterPosition < utf8Bytes.Length; characterPosition++) {
|
||||
byte currentCharacter = utf8Bytes[characterPosition];
|
||||
|
||||
if (currentCharacter == 0x00 || currentCharacter == 0x20 || currentCharacter > characterValues.Length || characterValues[currentCharacter] != null) {
|
||||
// character needs to be encoded
|
||||
char[] encodedCharacter;
|
||||
|
||||
if (currentCharacter == 0x20) {
|
||||
switch (encodingType) {
|
||||
case EncodingType.QueryString:
|
||||
encodedCharacter = QueryStringSpace;
|
||||
break;
|
||||
|
||||
// Special case for Html Form data, from http://www.w3.org/TR/html401/appendix/notes.html#non-ascii-chars
|
||||
case EncodingType.HtmlForm:
|
||||
encodedCharacter = FormStringSpace;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException("encodingType");
|
||||
}
|
||||
}
|
||||
else {
|
||||
encodedCharacter = characterValues[currentCharacter];
|
||||
}
|
||||
|
||||
for (int j = 0; j < encodedCharacter.Length; j++) {
|
||||
encodedInput[outputLength++] = encodedCharacter[j];
|
||||
}
|
||||
}
|
||||
else {
|
||||
// character does not need encoding
|
||||
encodedInput[outputLength++] = (char)currentCharacter;
|
||||
}
|
||||
}
|
||||
|
||||
return new string(encodedInput, 0, outputLength);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the HTML safe list.
|
||||
/// </summary>
|
||||
private static char[][] InitialiseSafeList() {
|
||||
char[][] result = SafeList.Generate(255, SafeList.PercentThenHexValueGenerator);
|
||||
SafeList.PunchSafeList(ref result, UrlParameterSafeList());
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for URL parameter encoding.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for URL parameter encoding.</returns>
|
||||
private static IEnumerable UrlParameterSafeList() {
|
||||
// Hyphen
|
||||
yield return 0x2D;
|
||||
|
||||
// Full stop/period
|
||||
yield return 0x2E;
|
||||
|
||||
// Digits
|
||||
for (int i = 0x30; i <= 0x39; i++) {
|
||||
yield return i;
|
||||
}
|
||||
|
||||
// Upper case alphabet
|
||||
for (int i = 0x41; i <= 0x5A; i++) {
|
||||
yield return i;
|
||||
}
|
||||
|
||||
// Underscore
|
||||
yield return 0x5F;
|
||||
|
||||
// Lower case alphabet
|
||||
for (int i = 0x61; i <= 0x7A; i++) {
|
||||
yield return i;
|
||||
}
|
||||
|
||||
// Tilde
|
||||
yield return 0x7E;
|
||||
}
|
||||
|
||||
#region UrlPathEncode Helpers
|
||||
|
||||
/// <summary>
|
||||
/// The values to output for each character.
|
||||
/// </summary>
|
||||
private static Lazy<char[][]> pathCharacterValuesLazy = new Lazy<char[][]>(InitialisePathSafeList);
|
||||
|
||||
internal static string UrlPathEncode(string s, Encoding encoding) {
|
||||
return FormQueryEncode(s, encoding, EncodingType.QueryString, pathCharacterValuesLazy);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the HTML safe list.
|
||||
/// </summary>
|
||||
private static char[][] InitialisePathSafeList() {
|
||||
char[][] result = SafeList.Generate(255, SafeList.PercentThenHexValueGenerator);
|
||||
SafeList.PunchSafeList(ref result, UrlPathSafeList());
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the safe characters for URL path encoding.
|
||||
/// </summary>
|
||||
/// <returns>The safe characters for URL path encoding.</returns>
|
||||
private static IEnumerable UrlPathSafeList() {
|
||||
|
||||
foreach (var c in UrlParameterSafeList()) {
|
||||
yield return c;
|
||||
}
|
||||
|
||||
// Hash
|
||||
yield return 0x23;
|
||||
|
||||
// Percent
|
||||
yield return 0x25;
|
||||
|
||||
// Forward slash
|
||||
yield return 0x2F;
|
||||
|
||||
// Backwards slash
|
||||
yield return 0x5C;
|
||||
|
||||
// Left parenthesis
|
||||
yield return 0x28;
|
||||
|
||||
//Right parenthesis
|
||||
yield return 0x29;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -0,0 +1,473 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="SafeList.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.Security.AntiXss {
|
||||
using System.Collections;
|
||||
using System.Globalization;
|
||||
|
||||
/// <summary>
|
||||
/// Provides safe list utility functions.
|
||||
/// </summary>
|
||||
internal static class SafeList {
|
||||
/// <summary>
|
||||
/// Generates a safe character array representing the specified value.
|
||||
/// </summary>
|
||||
/// <returns>A safe character array representing the specified value.</returns>
|
||||
/// <param name="value">The value to generate a safe representation for.</param>
|
||||
internal delegate char[] GenerateSafeValue(int value);
|
||||
|
||||
/// <summary>
|
||||
/// Generates a new safe list of the specified size, using the specified function to produce safe values.
|
||||
/// </summary>
|
||||
/// <param name="length">The length of the safe list to generate.</param>
|
||||
/// <param name="generateSafeValue">The <see cref="GenerateSafeValue"/> function to use.</param>
|
||||
/// <returns>A new safe list.</returns>
|
||||
internal static char[][] Generate(int length, GenerateSafeValue generateSafeValue) {
|
||||
char[][] allCharacters = new char[length + 1][];
|
||||
for (int i = 0; i <= length; i++) {
|
||||
allCharacters[i] = generateSafeValue(i);
|
||||
}
|
||||
|
||||
return allCharacters;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Marks characters from the specified languages as safe.
|
||||
/// </summary>
|
||||
/// <param name="safeList">The safe list to punch holes in.</param>
|
||||
/// <param name="lowerCodeCharts">The combination of lower code charts to use.</param>
|
||||
/// <param name="lowerMidCodeCharts">The combination of lower mid code charts to use.</param>
|
||||
/// <param name="midCodeCharts">The combination of mid code charts to use.</param>
|
||||
/// <param name="upperMidCodeCharts">The combination of upper mid code charts to use.</param>
|
||||
/// <param name="upperCodeCharts">The combination of upper code charts to use.</param>
|
||||
internal static void PunchUnicodeThrough(
|
||||
ref char[][] safeList,
|
||||
LowerCodeCharts lowerCodeCharts,
|
||||
LowerMidCodeCharts lowerMidCodeCharts,
|
||||
MidCodeCharts midCodeCharts,
|
||||
UpperMidCodeCharts upperMidCodeCharts,
|
||||
UpperCodeCharts upperCodeCharts) {
|
||||
if (lowerCodeCharts != LowerCodeCharts.None) {
|
||||
PunchCodeCharts(ref safeList, lowerCodeCharts);
|
||||
}
|
||||
|
||||
if (lowerMidCodeCharts != LowerMidCodeCharts.None) {
|
||||
PunchCodeCharts(ref safeList, lowerMidCodeCharts);
|
||||
}
|
||||
|
||||
if (midCodeCharts != MidCodeCharts.None) {
|
||||
PunchCodeCharts(ref safeList, midCodeCharts);
|
||||
}
|
||||
|
||||
if (upperMidCodeCharts != UpperMidCodeCharts.None) {
|
||||
PunchCodeCharts(ref safeList, upperMidCodeCharts);
|
||||
}
|
||||
|
||||
if (upperCodeCharts != UpperCodeCharts.None) {
|
||||
PunchCodeCharts(ref safeList, upperCodeCharts);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Punches holes as necessary.
|
||||
/// </summary>
|
||||
/// <param name="safeList">The safe list to punch through.</param>
|
||||
/// <param name="----edCharacters">The list of character positions to punch.</param>
|
||||
internal static void PunchSafeList(ref char[][] safeList, IEnumerable whiteListedCharacters) {
|
||||
PunchHolesIfNeeded(ref safeList, true, whiteListedCharacters);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a hash prefixed character array representing the specified value.
|
||||
/// </summary>
|
||||
/// <param name="value">The source value.</param>
|
||||
/// <returns>A character array representing the specified value.</returns>
|
||||
/// <remarks>
|
||||
/// Example inputs and encoded outputs:
|
||||
/// <list type="table">
|
||||
/// <item><term>1</term><description>#1</description></item>
|
||||
/// <item><term>10</term><description>#10</description></item>
|
||||
/// <item><term>100</term><description>#100</description></item>
|
||||
/// </list>
|
||||
/// </remarks>
|
||||
internal static char[] HashThenValueGenerator(int value) {
|
||||
return StringToCharArrayWithHashPrefix(value.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a hash prefixed character array representing the specified value in hexadecimal.
|
||||
/// </summary>
|
||||
/// <param name="value">The source value.</param>
|
||||
/// <returns>A character array representing the specified value.</returns>
|
||||
/// <remarks>
|
||||
/// Example inputs and encoded outputs:
|
||||
/// <list type="table">
|
||||
/// <item><term>1</term><description>#1</description></item>
|
||||
/// <item><term>10</term><description>#0a</description></item>
|
||||
/// <item><term>100</term><description>#64</description></item>
|
||||
/// </list>
|
||||
/// </remarks>
|
||||
internal static char[] HashThenHexValueGenerator(int value) {
|
||||
return StringToCharArrayWithHashPrefix(value.ToString("x2", CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a percent prefixed character array representing the specified value in hexadecimal.
|
||||
/// </summary>
|
||||
/// <param name="value">The source value.</param>
|
||||
/// <returns>A character array representing the specified value.</returns>
|
||||
/// <remarks>
|
||||
/// Example inputs and encoded outputs:
|
||||
/// <list type="table">
|
||||
/// <item><term>1</term><description>%01</description></item>
|
||||
/// <item><term>10</term><description>%0A</description></item>
|
||||
/// <item><term>100</term><description>%64</description></item>
|
||||
/// </list>
|
||||
/// </remarks>
|
||||
internal static char[] PercentThenHexValueGenerator(int value) {
|
||||
return StringToCharArrayWithPercentPrefix(value.ToString("X2", CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a slash prefixed character array representing the specified value in hexadecimal.
|
||||
/// </summary>
|
||||
/// <param name="value">The source value.</param>
|
||||
/// <returns>A character array representing the specified value.</returns>
|
||||
/// <remarks>
|
||||
/// Example inputs and encoded outputs:
|
||||
/// <list type="table">
|
||||
/// <item><term>1</term><description>\01</description></item>
|
||||
/// <item><term>10</term><description>\0a</description></item>
|
||||
/// <item><term>100</term><description>\64</description></item>
|
||||
/// </list>
|
||||
/// </remarks>
|
||||
internal static char[] SlashThenHexValueGenerator(int value) {
|
||||
return StringToCharArrayWithSlashPrefix(value.ToString("x2", CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a slash prefixed character array representing the specified value in hexadecimal.
|
||||
/// </summary>
|
||||
/// <param name="value">The source value.</param>
|
||||
/// <returns>A character array representing the specified value.</returns>
|
||||
/// <remarks>
|
||||
/// Example inputs and encoded outputs:
|
||||
/// <list type="table">
|
||||
/// <item><term>1</term><description>\000001</description></item>
|
||||
/// <item><term>10</term><description>\000000A</description></item>
|
||||
/// <item><term>100</term><description>\000064</description></item>
|
||||
/// </list>
|
||||
/// </remarks>
|
||||
internal static char[] SlashThenSixDigitHexValueGenerator(long value) {
|
||||
return StringToCharArrayWithSlashPrefix(value.ToString("X6", CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a slash prefixed character array representing the specified value in hexadecimal.
|
||||
/// </summary>
|
||||
/// <param name="value">The source value.</param>
|
||||
/// <returns>A character array representing the specified value.</returns>
|
||||
/// <remarks>
|
||||
/// Example inputs and encoded outputs:
|
||||
/// <list type="table">
|
||||
/// <item><term>1</term><description>\000001</description></item>
|
||||
/// <item><term>10</term><description>\000000A</description></item>
|
||||
/// <item><term>100</term><description>\000064</description></item>
|
||||
/// </list>
|
||||
/// </remarks>
|
||||
internal static char[] SlashThenSixDigitHexValueGenerator(int value) {
|
||||
return StringToCharArrayWithSlashPrefix(value.ToString("X6", CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a hash prefixed character array representing the specified value.
|
||||
/// </summary>
|
||||
/// <param name="value">The source value.</param>
|
||||
/// <returns>A character array representing the specified value.</returns>
|
||||
/// <remarks>
|
||||
/// Example inputs and encoded outputs:
|
||||
/// <list type="table">
|
||||
/// <item><term>1</term><description>#1</description></item>
|
||||
/// <item><term>10</term><description>#10</description></item>
|
||||
/// <item><term>100</term><description>#100</description></item>
|
||||
/// </list>
|
||||
/// </remarks>
|
||||
internal static char[] HashThenValueGenerator(long value) {
|
||||
return StringToCharArrayWithHashPrefix(value.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a hash prefixed character array from the specified string.
|
||||
/// </summary>
|
||||
/// <param name="value">The source value.</param>
|
||||
/// <returns>A character array representing the specified value.</returns>
|
||||
/// <remarks>
|
||||
/// Example inputs and encoded outputs:
|
||||
/// <list type="table">
|
||||
/// <item><term>1</term><description>#1</description></item>
|
||||
/// <item><term>10</term><description>#10</description></item>
|
||||
/// <item><term>100</term><description>#100</description></item>
|
||||
/// </list>
|
||||
/// </remarks>
|
||||
private static char[] StringToCharArrayWithHashPrefix(string value) {
|
||||
return StringToCharArrayWithPrefix(value, '#');
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a percent prefixed character array from the specified string.
|
||||
/// </summary>
|
||||
/// <param name="value">The source value.</param>
|
||||
/// <returns>A character array representing the specified value.</returns>
|
||||
/// <remarks>
|
||||
/// Example inputs and encoded outputs:
|
||||
/// <list type="table">
|
||||
/// <item><term>1</term><description>%1</description></item>
|
||||
/// <item><term>10</term><description>%10</description></item>
|
||||
/// <item><term>100</term><description>%100</description></item>
|
||||
/// </list>
|
||||
/// </remarks>
|
||||
private static char[] StringToCharArrayWithPercentPrefix(string value) {
|
||||
return StringToCharArrayWithPrefix(value, '%');
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a slash prefixed character array from the specified string.
|
||||
/// </summary>
|
||||
/// <param name="value">The source value.</param>
|
||||
/// <returns>A character array representing the specified value.</returns>
|
||||
/// <remarks>
|
||||
/// Example inputs and encoded outputs:
|
||||
/// <list type="table">
|
||||
/// <item><term>1</term><description>\1</description></item>
|
||||
/// <item><term>10</term><description>\10</description></item>
|
||||
/// <item><term>100</term><description>\100</description></item>
|
||||
/// </list>
|
||||
/// </remarks>
|
||||
private static char[] StringToCharArrayWithSlashPrefix(string value) {
|
||||
return StringToCharArrayWithPrefix(value, '\\');
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a prefixed character array from the specified string and prefix.
|
||||
/// </summary>
|
||||
/// <param name="value">The source value.</param>
|
||||
/// <param name="prefix">The prefix to use.</param>
|
||||
/// <returns>A prefixed character array representing the specified value.</returns>
|
||||
private static char[] StringToCharArrayWithPrefix(string value, char prefix) {
|
||||
int valueAsStringLength = value.Length;
|
||||
|
||||
char[] valueAsCharArray = new char[valueAsStringLength + 1];
|
||||
valueAsCharArray[0] = prefix;
|
||||
for (int j = 0; j < valueAsStringLength; j++) {
|
||||
valueAsCharArray[j + 1] = value[j];
|
||||
}
|
||||
|
||||
return valueAsCharArray;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Punch appropriate holes for the selected code charts.
|
||||
/// </summary>
|
||||
/// <param name="safeList">The safe list to punch through.</param>
|
||||
/// <param name="codeCharts">The code charts to punch.</param>
|
||||
private static void PunchCodeCharts(ref char[][] safeList, LowerCodeCharts codeCharts) {
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.BasicLatin), CodeCharts.Lower.BasicLatin());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.C1ControlsAndLatin1Supplement), CodeCharts.Lower.Latin1Supplement());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.LatinExtendedA), CodeCharts.Lower.LatinExtendedA());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.LatinExtendedB), CodeCharts.Lower.LatinExtendedB());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.IpaExtensions), CodeCharts.Lower.IpaExtensions());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.SpacingModifierLetters), CodeCharts.Lower.SpacingModifierLetters());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.CombiningDiacriticalMarks), CodeCharts.Lower.CombiningDiacriticalMarks());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.GreekAndCoptic), CodeCharts.Lower.GreekAndCoptic());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Cyrillic), CodeCharts.Lower.Cyrillic());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.CyrillicSupplement), CodeCharts.Lower.CyrillicSupplement());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Armenian), CodeCharts.Lower.Armenian());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Hebrew), CodeCharts.Lower.Hebrew());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Arabic), CodeCharts.Lower.Arabic());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Syriac), CodeCharts.Lower.Syriac());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.ArabicSupplement), CodeCharts.Lower.ArabicSupplement());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Thaana), CodeCharts.Lower.Thaana());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Nko), CodeCharts.Lower.Nko());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Samaritan), CodeCharts.Lower.Samaritan());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Devanagari), CodeCharts.Lower.Devanagari());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Bengali), CodeCharts.Lower.Bengali());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Gurmukhi), CodeCharts.Lower.Gurmukhi());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Gujarati), CodeCharts.Lower.Gujarati());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Oriya), CodeCharts.Lower.Oriya());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Tamil), CodeCharts.Lower.Tamil());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Telugu), CodeCharts.Lower.Telugu());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Kannada), CodeCharts.Lower.Kannada());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Malayalam), CodeCharts.Lower.Malayalam());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Sinhala), CodeCharts.Lower.Sinhala());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Thai), CodeCharts.Lower.Thai());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Lao), CodeCharts.Lower.Lao());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Tibetan), CodeCharts.Lower.Tibetan());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Punch appropriate holes for the selected code charts.
|
||||
/// </summary>
|
||||
/// <param name="safeList">The safe list to punch through.</param>
|
||||
/// <param name="codeCharts">The code charts to punch.</param>
|
||||
private static void PunchCodeCharts(ref char[][] safeList, LowerMidCodeCharts codeCharts) {
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.Myanmar), CodeCharts.LowerMiddle.Myanmar());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.Georgian), CodeCharts.LowerMiddle.Georgian());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.HangulJamo), CodeCharts.LowerMiddle.HangulJamo());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.Ethiopic), CodeCharts.LowerMiddle.Ethiopic());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.EthiopicSupplement), CodeCharts.LowerMiddle.EthiopicSupplement());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.Cherokee), CodeCharts.LowerMiddle.Cherokee());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.UnifiedCanadianAboriginalSyllabics), CodeCharts.LowerMiddle.UnifiedCanadianAboriginalSyllabics());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.Ogham), CodeCharts.LowerMiddle.Ogham());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.Runic), CodeCharts.LowerMiddle.Runic());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.Tagalog), CodeCharts.LowerMiddle.Tagalog());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.Hanunoo), CodeCharts.LowerMiddle.Hanunoo());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.Buhid), CodeCharts.LowerMiddle.Buhid());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.Tagbanwa), CodeCharts.LowerMiddle.Tagbanwa());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.Khmer), CodeCharts.LowerMiddle.Khmer());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.Mongolian), CodeCharts.LowerMiddle.Mongolian());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.UnifiedCanadianAboriginalSyllabicsExtended), CodeCharts.LowerMiddle.UnifiedCanadianAboriginalSyllabicsExtended());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.Limbu), CodeCharts.LowerMiddle.Limbu());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.TaiLe), CodeCharts.LowerMiddle.TaiLe());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.NewTaiLue), CodeCharts.LowerMiddle.NewTaiLue());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.KhmerSymbols), CodeCharts.LowerMiddle.KhmerSymbols());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.Buginese), CodeCharts.LowerMiddle.Buginese());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.TaiTham), CodeCharts.LowerMiddle.TaiTham());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.Balinese), CodeCharts.LowerMiddle.Balinese());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.Sudanese), CodeCharts.LowerMiddle.Sudanese());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.Lepcha), CodeCharts.LowerMiddle.Lepcha());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.OlChiki), CodeCharts.LowerMiddle.OlChiki());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.VedicExtensions), CodeCharts.LowerMiddle.VedicExtensions());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.PhoneticExtensions), CodeCharts.LowerMiddle.PhoneticExtensions());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.PhoneticExtensionsSupplement), CodeCharts.LowerMiddle.PhoneticExtensionsSupplement());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.CombiningDiacriticalMarksSupplement), CodeCharts.LowerMiddle.CombiningDiacriticalMarksSupplement());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.LatinExtendedAdditional), CodeCharts.LowerMiddle.LatinExtendedAdditional());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Punch appropriate holes for the selected code charts.
|
||||
/// </summary>
|
||||
/// <param name="safeList">The safe list to punch through.</param>
|
||||
/// <param name="codeCharts">The code charts to punch.</param>
|
||||
private static void PunchCodeCharts(ref char[][] safeList, MidCodeCharts codeCharts) {
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.GreekExtended), CodeCharts.Middle.GreekExtended());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.GeneralPunctuation), CodeCharts.Middle.GeneralPunctuation());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.SuperscriptsAndSubscripts), CodeCharts.Middle.SuperscriptsAndSubscripts());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.CurrencySymbols), CodeCharts.Middle.CurrencySymbols());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.CombiningDiacriticalMarksForSymbols), CodeCharts.Middle.CombiningDiacriticalMarksForSymbols());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.LetterlikeSymbols), CodeCharts.Middle.LetterlikeSymbols());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.NumberForms), CodeCharts.Middle.NumberForms());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.Arrows), CodeCharts.Middle.Arrows());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.MathematicalOperators), CodeCharts.Middle.MathematicalOperators());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.MiscellaneousTechnical), CodeCharts.Middle.MiscellaneousTechnical());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.ControlPictures), CodeCharts.Middle.ControlPictures());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.OpticalCharacterRecognition), CodeCharts.Middle.OpticalCharacterRecognition());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.EnclosedAlphanumerics), CodeCharts.Middle.EnclosedAlphanumerics());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.BoxDrawing), CodeCharts.Middle.BoxDrawing());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.BlockElements), CodeCharts.Middle.BlockElements());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.GeometricShapes), CodeCharts.Middle.GeometricShapes());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.MiscellaneousSymbols), CodeCharts.Middle.MiscellaneousSymbols());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.Dingbats), CodeCharts.Middle.Dingbats());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.MiscellaneousMathematicalSymbolsA), CodeCharts.Middle.MiscellaneousMathematicalSymbolsA());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.SupplementalArrowsA), CodeCharts.Middle.SupplementalArrowsA());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.BraillePatterns), CodeCharts.Middle.BraillePatterns());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.SupplementalArrowsB), CodeCharts.Middle.SupplementalArrowsB());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.MiscellaneousMathematicalSymbolsB), CodeCharts.Middle.MiscellaneousMathematicalSymbolsB());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.SupplementalMathematicalOperators), CodeCharts.Middle.SupplementalMathematicalOperators());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.MiscellaneousSymbolsAndArrows), CodeCharts.Middle.MiscellaneousSymbolsAndArrows());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.Glagolitic), CodeCharts.Middle.Glagolitic());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.LatinExtendedC), CodeCharts.Middle.LatinExtendedC());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.Coptic), CodeCharts.Middle.Coptic());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.GeorgianSupplement), CodeCharts.Middle.GeorgianSupplement());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.Tifinagh), CodeCharts.Middle.Tifinagh());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.EthiopicExtended), CodeCharts.Middle.EthiopicExtended());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Punch appropriate holes for the selected code charts.
|
||||
/// </summary>
|
||||
/// <param name="safeList">The safe list to punch through.</param>
|
||||
/// <param name="codeCharts">The code charts to punch.</param>
|
||||
private static void PunchCodeCharts(ref char[][] safeList, UpperMidCodeCharts codeCharts) {
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.CyrillicExtendedA), CodeCharts.UpperMiddle.CyrillicExtendedA());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.SupplementalPunctuation), CodeCharts.UpperMiddle.SupplementalPunctuation());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.CjkRadicalsSupplement), CodeCharts.UpperMiddle.CjkRadicalsSupplement());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.KangxiRadicals), CodeCharts.UpperMiddle.KangxiRadicals());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.IdeographicDescriptionCharacters), CodeCharts.UpperMiddle.IdeographicDescriptionCharacters());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.CjkSymbolsAndPunctuation), CodeCharts.UpperMiddle.CjkSymbolsAndPunctuation());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.Hiragana), CodeCharts.UpperMiddle.Hiragana());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.Katakana), CodeCharts.UpperMiddle.Katakana());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.Bopomofo), CodeCharts.UpperMiddle.Bopomofo());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.HangulCompatibilityJamo), CodeCharts.UpperMiddle.HangulCompatibilityJamo());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.Kanbun), CodeCharts.UpperMiddle.Kanbun());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.BopomofoExtended), CodeCharts.UpperMiddle.BopomofoExtended());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.CjkStrokes), CodeCharts.UpperMiddle.CjkStrokes());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.KatakanaPhoneticExtensions), CodeCharts.UpperMiddle.KatakanaPhoneticExtensions());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.EnclosedCjkLettersAndMonths), CodeCharts.UpperMiddle.EnclosedCjkLettersAndMonths());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.CjkCompatibility), CodeCharts.UpperMiddle.CjkCompatibility());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.CjkUnifiedIdeographsExtensionA), CodeCharts.UpperMiddle.CjkUnifiedIdeographsExtensionA());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.YijingHexagramSymbols), CodeCharts.UpperMiddle.YijingHexagramSymbols());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.CjkUnifiedIdeographs), CodeCharts.UpperMiddle.CjkUnifiedIdeographs());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.YiSyllables), CodeCharts.UpperMiddle.YiSyllables());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.YiRadicals), CodeCharts.UpperMiddle.YiRadicals());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.Lisu), CodeCharts.UpperMiddle.Lisu());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.Vai), CodeCharts.UpperMiddle.Vai());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.CyrillicExtendedB), CodeCharts.UpperMiddle.CyrillicExtendedB());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.Bamum), CodeCharts.UpperMiddle.Bamum());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.ModifierToneLetters), CodeCharts.UpperMiddle.ModifierToneLetters());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.LatinExtendedD), CodeCharts.UpperMiddle.LatinExtendedD());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.SylotiNagri), CodeCharts.UpperMiddle.SylotiNagri());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.CommonIndicNumberForms), CodeCharts.UpperMiddle.CommonIndicNumberForms());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.Phagspa), CodeCharts.UpperMiddle.Phagspa());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.Saurashtra), CodeCharts.UpperMiddle.Saurashtra());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Punch appropriate holes for the selected code charts.
|
||||
/// </summary>
|
||||
/// <param name="safeList">The safe list to punch through.</param>
|
||||
/// <param name="codeCharts">The code charts to punch.</param>
|
||||
private static void PunchCodeCharts(ref char[][] safeList, UpperCodeCharts codeCharts) {
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.DevanagariExtended), CodeCharts.Upper.DevanagariExtended());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.KayahLi), CodeCharts.Upper.KayahLi());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.Rejang), CodeCharts.Upper.Rejang());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.HangulJamoExtendedA), CodeCharts.Upper.HangulJamoExtendedA());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.Javanese), CodeCharts.Upper.Javanese());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.Cham), CodeCharts.Upper.Cham());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.MyanmarExtendedA), CodeCharts.Upper.MyanmarExtendedA());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.TaiViet), CodeCharts.Upper.TaiViet());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.MeeteiMayek), CodeCharts.Upper.MeeteiMayek());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.HangulSyllables), CodeCharts.Upper.HangulSyllables());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.HangulJamoExtendedB), CodeCharts.Upper.HangulJamoExtendedB());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.CjkCompatibilityIdeographs), CodeCharts.Upper.CjkCompatibilityIdeographs());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.AlphabeticPresentationForms), CodeCharts.Upper.AlphabeticPresentationForms());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.ArabicPresentationFormsA), CodeCharts.Upper.ArabicPresentationFormsA());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.VariationSelectors), CodeCharts.Upper.VariationSelectors());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.VerticalForms), CodeCharts.Upper.VerticalForms());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.CombiningHalfMarks), CodeCharts.Upper.CombiningHalfMarks());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.CjkCompatibilityForms), CodeCharts.Upper.CjkCompatibilityForms());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.SmallFormVariants), CodeCharts.Upper.SmallFormVariants());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.ArabicPresentationFormsB), CodeCharts.Upper.ArabicPresentationFormsB());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.HalfWidthAndFullWidthForms), CodeCharts.Upper.HalfWidthAndFullWidthForms());
|
||||
PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.Specials), CodeCharts.Upper.Specials());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Punches holes as necessary.
|
||||
/// </summary>
|
||||
/// <param name="safeList">The safe list to punch through.</param>
|
||||
/// <param name="isNeeded">Value indicating whether the holes should be punched.</param>
|
||||
/// <param name="----edCharacters">The list of character positions to punch.</param>
|
||||
private static void PunchHolesIfNeeded(ref char[][] safeList, bool isNeeded, IEnumerable whiteListedCharacters) {
|
||||
if (!isNeeded) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (int offset in whiteListedCharacters) {
|
||||
safeList[offset] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,126 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="Utf16StringReader.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.Security.AntiXss {
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
/// <summary>
|
||||
/// Reads individual scalar values from a UTF-16 input string.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// For performance reasons, this is a mutable struct. Use caution when capturing instances of this type.
|
||||
/// </remarks>
|
||||
internal struct Utf16StringReader {
|
||||
|
||||
/// <summary>
|
||||
/// Starting code point for the UTF-16 leading surrogates.
|
||||
/// </summary>
|
||||
private const char LeadingSurrogateStart = '\uD800';
|
||||
|
||||
/// <summary>
|
||||
/// Starting code point for the UTF-16 trailing surrogates.
|
||||
/// </summary>
|
||||
private const char TrailingSurrogateStart = '\uDC00';
|
||||
|
||||
/// <summary>
|
||||
/// The Unicode replacement character U+FFFD.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// For more info, see http://www.unicode.org/charts/PDF/UFFF0.pdf.
|
||||
/// </remarks>
|
||||
private const int UnicodeReplacementCharacterCodePoint = '\uFFFD';
|
||||
|
||||
/// <summary>
|
||||
/// The current offset into '_input'.
|
||||
/// </summary>
|
||||
private int _currentOffset;
|
||||
|
||||
/// <summary>
|
||||
/// The input string we're iterating on.
|
||||
/// </summary>
|
||||
private readonly string _input;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the reader with the given UTF-16 input string.
|
||||
/// </summary>
|
||||
/// <param name="input">The input string to decompose into scalar values.</param>
|
||||
public Utf16StringReader(string input) {
|
||||
Debug.Assert(input != null);
|
||||
|
||||
_input = input;
|
||||
_currentOffset = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Similar to Char.ConvertToUtf32, but slightly faster in tight loops since parameter checks are not done.
|
||||
/// </summary>
|
||||
/// <param name="leadingSurrogate">The UTF-16 leading surrogate character.</param>
|
||||
/// <param name="trailingSurrogate">The UTF-16 trailing surrogate character.</param>
|
||||
/// <returns>The scalar value resulting from combining these two surrogate characters.</returns>
|
||||
/// <remarks>The caller must ensure that the inputs are valid surrogate characters. If not,
|
||||
/// the output of this routine is undefined.</remarks>
|
||||
private static int ConvertToUtf32(char leadingSurrogate, char trailingSurrogate) {
|
||||
Debug.Assert(Char.IsHighSurrogate(leadingSurrogate), "'leadingSurrogate' was not a high surrogate.");
|
||||
Debug.Assert(Char.IsLowSurrogate(trailingSurrogate), "'trailingSurrogate' was not a low surrogate.");
|
||||
|
||||
return (int)((leadingSurrogate - LeadingSurrogateStart) * 0x400 + (trailingSurrogate - TrailingSurrogateStart)) + 0x10000;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether a given code point is a valid Unicode scalar value.
|
||||
/// </summary>
|
||||
/// <param name="codePoint">The code point whose validity is to be checked.</param>
|
||||
/// <returns>True if the input is a valid Unicode scalar value, false otherwise.</returns>
|
||||
private static bool IsValidUnicodeScalarValue(int codePoint) {
|
||||
// Valid scalar values are U+0000 .. U+D7FF and U+E000 .. U+10FFFF.
|
||||
// See: http://www.unicode.org/versions/Unicode6.0.0/ch03.pdf, D76
|
||||
return (0 <= codePoint && codePoint <= 0xD7FF)
|
||||
|| (0xE000 <= codePoint && codePoint <= 0x10FFFF);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the next scalar value from the input string.
|
||||
/// </summary>
|
||||
/// <returns>The next scalar value. If the input string contains invalid UTF-16, the
|
||||
/// return value is the Unicode replacement character U+FFFD. If the end of the string
|
||||
/// is reached, returns -1.</returns>
|
||||
public int ReadNextScalarValue() {
|
||||
if (_currentOffset >= _input.Length) {
|
||||
return -1; // EOF
|
||||
}
|
||||
|
||||
char thisCodeUnit = _input[_currentOffset++];
|
||||
int thisCodePoint = thisCodeUnit;
|
||||
|
||||
if (Char.IsHighSurrogate(thisCodeUnit)) {
|
||||
if (_currentOffset < _input.Length) {
|
||||
char nextCodeUnit = _input[_currentOffset];
|
||||
if (Char.IsLowSurrogate(nextCodeUnit)) {
|
||||
// We encountered a high (leading) surrogate followed by a low
|
||||
// (trailing) surrogate. Bump '_currentOffset' up by one more
|
||||
// since we're consuming both code units.
|
||||
_currentOffset++;
|
||||
thisCodePoint = ConvertToUtf32(thisCodeUnit, nextCodeUnit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (IsValidUnicodeScalarValue(thisCodePoint)) {
|
||||
return thisCodePoint;
|
||||
}
|
||||
else {
|
||||
// ERROR: This code point was either an unmatched high (leading)
|
||||
// surrogate or an unmatched low (trailing) surrogate, neither of
|
||||
// which maps to a valid Unicode scalar value. Per the Unicode
|
||||
// specification (Ch. 3, C10), we replace with U+FFFD.
|
||||
return UnicodeReplacementCharacterCodePoint;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,209 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="BackStopAuthenticationModule.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.Security {
|
||||
using System.Collections.Specialized;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Security.Principal;
|
||||
using System.Security.Permissions;
|
||||
using System.Threading;
|
||||
using System.Web;
|
||||
|
||||
|
||||
/// <devdoc>
|
||||
/// <para>[To be supplied.]</para>
|
||||
/// </devdoc>
|
||||
public sealed class DefaultAuthenticationModule : IHttpModule {
|
||||
private DefaultAuthenticationEventHandler _eventHandler;
|
||||
|
||||
|
||||
/// <devdoc>
|
||||
/// <para>
|
||||
/// Initializes a new instance of the <see cref='System.Web.Security.DefaultAuthenticationModule'/>
|
||||
/// class.
|
||||
/// </para>
|
||||
/// </devdoc>
|
||||
[SecurityPermission(SecurityAction.Demand, Unrestricted=true)]
|
||||
public DefaultAuthenticationModule() {
|
||||
}
|
||||
|
||||
[SecurityPermission(SecurityAction.Assert, Unrestricted = true)]
|
||||
internal static DefaultAuthenticationModule CreateDefaultAuthenticationModuleWithAssert() {
|
||||
return new DefaultAuthenticationModule();
|
||||
}
|
||||
|
||||
/// <devdoc>
|
||||
/// <para>[To be supplied.]</para>
|
||||
/// </devdoc>
|
||||
public event DefaultAuthenticationEventHandler Authenticate {
|
||||
add {
|
||||
// WOS 1709222: DefaultAuthentication_Authenticate is not supported in integrated mode.
|
||||
if (HttpRuntime.UseIntegratedPipeline) {
|
||||
throw new PlatformNotSupportedException(SR.GetString(SR.Method_Not_Supported_By_Iis_Integrated_Mode, "DefaultAuthentication.Authenticate"));
|
||||
}
|
||||
_eventHandler += value;
|
||||
}
|
||||
remove {
|
||||
_eventHandler -= value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <devdoc>
|
||||
/// <para>[To be supplied.]</para>
|
||||
/// </devdoc>
|
||||
public void Dispose() {
|
||||
}
|
||||
|
||||
|
||||
/// <devdoc>
|
||||
/// <para>[To be supplied.]</para>
|
||||
/// </devdoc>
|
||||
public void Init(HttpApplication app) {
|
||||
// adding this module back to IIS7
|
||||
// it needs to run between Windows auth in PostAuthn
|
||||
// and RoleManager (or anyone else who needs the principal)
|
||||
// so ordering is important
|
||||
// If the subscribed event changes, WindowsAuthenticationModule
|
||||
// needs work, too.
|
||||
if (HttpRuntime.UseIntegratedPipeline) {
|
||||
app.PostAuthenticateRequest += new EventHandler(this.OnEnter);
|
||||
}
|
||||
else {
|
||||
app.DefaultAuthentication += new EventHandler(this.OnEnter);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// OnAuthenticate: Custom Authentication modules can override
|
||||
// this method to create a custom IPrincipal object from
|
||||
// a DefaultIdentity
|
||||
void OnAuthenticate(DefaultAuthenticationEventArgs e) {
|
||||
////////////////////////////////////////////////////////////
|
||||
// If there are event handlers, invoke the handlers
|
||||
if (_eventHandler != null) {
|
||||
_eventHandler(this, e);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// AddOnAuthenticate and RemoveOnAuthenticate: Use these
|
||||
// methods to hook up event handlers to handle the
|
||||
// OnAuthenticate Event
|
||||
[SecurityPermission(SecurityAction.Assert, ControlPrincipal = true)]
|
||||
void OnEnter(Object source, EventArgs eventArgs) {
|
||||
HttpApplication app;
|
||||
HttpContext context;
|
||||
|
||||
app = (HttpApplication)source;
|
||||
context = app.Context;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Step 1: Check if authentication failed
|
||||
if (context.Response.StatusCode > 200) { // Invalid credentials
|
||||
if (context.Response.StatusCode == 401)
|
||||
WriteErrorMessage(context);
|
||||
|
||||
app.CompleteRequest();
|
||||
return;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Step 2: If no auth module has created an IPrincipal, then fire
|
||||
// OnAuthentication event
|
||||
if (context.User == null) {
|
||||
OnAuthenticate (new DefaultAuthenticationEventArgs(context) );
|
||||
if (context.Response.StatusCode > 200) { // Invalid credentials
|
||||
if (context.Response.StatusCode == 401)
|
||||
WriteErrorMessage(context);
|
||||
|
||||
app.CompleteRequest();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Step 3: Attach an anonymous user to this request, if none
|
||||
// of the authentication modules created a user
|
||||
if (context.User == null) {
|
||||
context.SetPrincipalNoDemand(new GenericPrincipal(new GenericIdentity(String.Empty, String.Empty), new String[0]), false /*needToSetNativePrincipal*/);
|
||||
}
|
||||
|
||||
Thread.CurrentPrincipal = context.User;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
void WriteErrorMessage(HttpContext context) {
|
||||
context.Response.Write(AuthFailedErrorFormatter.GetErrorText());
|
||||
// In Integrated pipeline, ask for handler headers to be generated. This would be unnecessary
|
||||
// if we just threw an access denied exception, and used the standard error mechanism
|
||||
context.Response.GenerateResponseHeadersForHandler();
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////
|
||||
internal class AuthFailedErrorFormatter : ErrorFormatter {
|
||||
private static string _strErrorText;
|
||||
private static object _syncObject = new object();
|
||||
|
||||
internal AuthFailedErrorFormatter() {
|
||||
}
|
||||
|
||||
internal /*public*/ static string GetErrorText() {
|
||||
if (_strErrorText != null)
|
||||
return _strErrorText;
|
||||
|
||||
lock(_syncObject) {
|
||||
if (_strErrorText == null)
|
||||
_strErrorText = (new AuthFailedErrorFormatter()).GetErrorMessage();
|
||||
}
|
||||
|
||||
return _strErrorText;
|
||||
}
|
||||
|
||||
protected override string ErrorTitle {
|
||||
get { return SR.GetString(SR.Assess_Denied_Title);}
|
||||
}
|
||||
|
||||
protected override string Description {
|
||||
get {
|
||||
return SR.GetString(SR.Assess_Denied_Description1);
|
||||
//"An error occurred while accessing the resources required to serve this request. This typically happens when you provide the wrong user-name and/or password.";
|
||||
}
|
||||
}
|
||||
|
||||
protected override string MiscSectionTitle {
|
||||
get { return SR.GetString(SR.Assess_Denied_MiscTitle1);}
|
||||
//"Error message 401.1";}
|
||||
}
|
||||
|
||||
protected override string MiscSectionContent {
|
||||
get {
|
||||
string miscContent = SR.GetString(SR.Assess_Denied_MiscContent1);
|
||||
AdaptiveMiscContent.Add(miscContent);
|
||||
return miscContent;
|
||||
//return "Logon credentials provided were not recognized. Make sure you are providing the correct user-name and password. Otherwise, ask the web server's administrator for help.";
|
||||
}
|
||||
}
|
||||
|
||||
protected override string ColoredSquareTitle {
|
||||
get { return null;}
|
||||
}
|
||||
|
||||
protected override string ColoredSquareContent {
|
||||
get { return null;}
|
||||
}
|
||||
|
||||
protected override bool ShowSourceFileInfo {
|
||||
get { return false;}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user