Index was outside the bounds of the array.

其他环境

提交数据时,下面这行代码报错

string answerExplain = WRequest.Form("Explain", FilterOption.Breakbr);

FilterOption.cs代码如下:

/// <summary>
    /// 过滤选项的属性类 枚举值每天加一种过滤方法,委托要添加相应的一个方法,需要要一直
    /// </summary>
    public struct FilterOptionInfo
    {
        public delegate string FilterMethod(string content);
        public static readonly int FitlerOptionLength = 10;
        /// <summary>
        /// 委托数组的顺序要和下面的相同
        /// </summary>
        public static readonly FilterMethod[] FilterMethodes = new FilterMethod[11] {
            Filter.FilterScriptPart,
            Filter.FilterHtml,
            Filter.FilterIframe,
            Filter.FilterStylePart,
            Filter.FilterAHref,
            Filter.FilterFrameset,
            Filter.FilterSrc,
            Filter.FilterObject,
            Filter.SingleQuotes,
            Filter.SpaceTrim
        };
    }
    public enum FilterOption
    {
        /// <summary>
        /// 过滤Javascript代码 00000001
        /// </summary>
        Script = 1,
        /// <summary>
        /// 过滤Html代码 00000010
        /// </summary>
        Html = 2,
        /// <summary>
        /// 过滤Iframe00000100
        /// </summary>
        IFrame = 4,
        /// <summary>
        /// 过滤css样式00001000
        /// </summary>
        Style = 8,
        /// <summary>
        /// 过滤Href连接00010000
        /// </summary>
        Href = 16,
        /// <summary>
        /// 框架集00100000
        /// </summary>
        FrameSet = 32,
            

最佳答案

原因分析

FilterOption增加了一个枚举“ Breakbr = 1024”,FilterMethodes 数组没有增加对应数据,导致枚举数量与数组长度不一致而引发的下标超限

FilterMethodes数组里增加 Filter.Breakbr

/// <summary>
    /// 过滤选项的属性类 枚举值每天加一种过滤方法,委托要添加相应的一个方法,需要要一直
    /// </summary>
    public struct FilterOptionInfo
    {
        public delegate string FilterMethod(string content);
        public static readonly int FitlerOptionLength = 10;
        /// <summary>
        /// 委托数组的顺序要和下面的相同
        /// </summary>
        public static readonly FilterMethod[] FilterMethodes = new FilterMethod[11] {
            Filter.FilterScriptPart,
            Filter.FilterHtml,
            Filter.FilterIframe,
            Filter.FilterStylePart,
            Filter.FilterAHref,
            Filter.FilterFrameset,
            Filter.FilterSrc,
            Filter.FilterObject,
            Filter.SingleQuotes,
            Filter.SpaceTrim,
	    Filter.Breakbr
        };
    }


desaco T0 被采纳率50%
2020-11-05 14:21
打赏 0 0
页面统计
202 访问
0 帮助
0.00 打赏

hierror 2019 © hierror.com 京ICP备13026190号-1

通知消息
  • 暂无任何消息