当前位置: 首页>>代码示例>>C#>>正文


C# HtmlTag.SetAttributeValue方法代码示例

本文整理汇总了C#中HtmlTag.SetAttributeValue方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlTag.SetAttributeValue方法的具体用法?C# HtmlTag.SetAttributeValue怎么用?C# HtmlTag.SetAttributeValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HtmlTag的用法示例。


在下文中一共展示了HtmlTag.SetAttributeValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UpdatingAttributeUpdatesTagIsValid

        public void UpdatingAttributeUpdatesTagIsValid()
        {
            const String orig = "<IMG src     =  \"keywords\"     content  =     \"1 + 1 = 2\">";
            const String updated = "<img src=\"keywords\" content=\"2 + 2 = 4\">";
            HtmlTag testTag = new HtmlTag(orig);
            Assert.IsTrue(testTag.AttrCount == 2, "Tag count is incorrect.  Got {0}, expected {1}", testTag.AttrCount, 2);
            Assert.IsTrue("\"1 + 1 = 2\"" == testTag.GetAttributeValue("content"), "Attribute value mismatch");

            testTag.SetAttributeValue("content", "\"2 + 2 = 4\"");
            Assert.IsTrue("\"2 + 2 = 4\"" == testTag.GetAttributeValue("content"), "Attribute value mismatch");

            // ensure modified string is what we expect. In this case, one change.
            Assert.IsTrue(updated == testTag.TagString, "Modified string does not match expected!");
        }
开发者ID:asr340,项目名称:owasp-code-central,代码行数:14,代码来源:HtmlTagTest.cs

示例2: InjectURLParameters

        private String InjectURLParameters(String htmlText)
        {
            StringBuilder newHtmlText = new StringBuilder();
            _log.Debug(App.Configuration.ExtensionWhitelistPattern);
            Regex extensionWhitelistRegex =
                new Regex(App.Configuration.ExtensionWhitelistPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
            Regex skipJavascriptRegex = new Regex("^javascript:", RegexOptions.Compiled | RegexOptions.IgnoreCase);

            for (int i = 0; i < htmlText.Length; i++)
            {
                switch (htmlText[i])
                {
                    case '<':
                        // got a tag start.  Let's grab the whole tag
                        String tagStr = Util.CaptureFromStartToStopChar(htmlText, i, '<', '>');
                        i += (tagStr.Length - 1); // advance the loop value ahead past this tag.
                        HtmlTag tagObj = new HtmlTag(tagStr);
                        String value;
                        if ((value = tagObj.GetAttributeValue("src")) != null)
                        {
                            // SECURITY NOTE:  enforce the same-origin policy for rewrites.  Only links for this site get rewritten!
                            if (Util.IsUrlSameOriginAsServer(Util.StripQuotes(value))
                                && !extensionWhitelistRegex.IsMatch(Util.StripQuotes(value)))
                            {
                                _log.Debug("Injecting token for src url '" + value + "'");
                                tagObj.SetAttributeValue("src",
                                                         InjectURLToken(value, _CSRFTokenName, _CSRFSesssionToken));
                            }
                        }
                        else if ((value = tagObj.GetAttributeValue("href")) != null)
                        {
                            // SECURITY NOTE:  enforce the same-origin policy for rewrites.  Only links for this site get rewritten!
                            if (Util.IsUrlSameOriginAsServer(Util.StripQuotes(value))
                                && !extensionWhitelistRegex.IsMatch(Util.StripQuotes(value))
                                && !skipJavascriptRegex.IsMatch(Util.StripQuotes(value)))
                                // don't break javascript hrefs
                            {
                                _log.Debug("Injecting token for href url " + value);
                                tagObj.SetAttributeValue("href",
                                                         InjectURLToken(value, _CSRFTokenName, _CSRFSesssionToken));
                            }
                        }

                        newHtmlText.Append(tagObj.TagString);
                        break;
                    case '>':
                        // should never get here since the end tag gets gobbled up by the CaptureFromStartToStopChar() method
                        _log.Warn("Supposedly unreachable parse error encountered in RegexFilter at char #" + i);
                        break;
                    default:
                        // anything else passes through without modification
                        newHtmlText.Append(htmlText[i]);
                        break;
                }
            }

            return newHtmlText.ToString();
        }
开发者ID:asr340,项目名称:owasp-code-central,代码行数:58,代码来源:RegexFilter.cs


注:本文中的HtmlTag.SetAttributeValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。