Beispiel #1
0
		/// <summary>
		/// Initializes a new instance of the <see cref="HtmlAttribute"/> class.
		/// </summary>
		/// <remarks>
		/// Creates a new HTML attribute with the given id and value.
		/// </remarks>
		/// <param name="id">The attribute identifier.</param>
		/// <param name="value">The attribute value.</param>
		/// <exception cref="System.ArgumentOutOfRangeException">
		/// <paramref name="id"/> is not a valid value.
		/// </exception>
		public HtmlAttribute (HtmlAttributeId id, string value)
		{
			if (id == HtmlAttributeId.Unknown)
				throw new ArgumentOutOfRangeException ("id");

			Name = id.ToAttributeName ();
			Value = value;
			Id = id;
		}
Beispiel #2
0
        /// <summary>
        /// Converts the enum value into the equivalent attribute name.
        /// </summary>
        /// <remarks>
        /// Converts the enum value into the equivalent attribute name.
        /// </remarks>
        /// <returns>The attribute name.</returns>
        /// <param name="value">The enum value.</param>
        public static string ToAttributeName(this HtmlAttributeId value)
        {
            var name = value.ToString();

#if PORTABLE || NETSTANDARD
            var field = typeof(HtmlAttributeId).GetTypeInfo().GetDeclaredField(name);
            var attrs = field.GetCustomAttributes(typeof(HtmlAttributeNameAttribute), false).ToArray();
#else
            var field = typeof(HtmlAttributeId).GetField(name);
            var attrs = field.GetCustomAttributes(typeof(HtmlAttributeNameAttribute), false);
#endif

            if (attrs != null && attrs.Length == 1)
            {
                return(((HtmlAttributeNameAttribute)attrs[0]).Name);
            }

            return(name.ToLowerInvariant());
        }
 protected static bool IsSafeUrl(string urlString, HtmlAttributeId htmlAttr)
 {
     SafeHtmlCallback.TypeOfUrl typeOfUrl = SafeHtmlCallback.GetTypeOfUrl(urlString, htmlAttr);
     return(typeOfUrl != SafeHtmlCallback.TypeOfUrl.Unknown);
 }
Beispiel #4
0
		/// <summary>
		/// Write the attribute name to the output stream.
		/// </summary>
		/// <remarks>
		/// Writes the attribute name to the output stream.
		/// </remarks>
		/// <param name="id">The attribute identifier.</param>
		/// <exception cref="System.ArgumentException">
		/// <paramref name="id"/> is not a valid HTML attribute identifier.
		/// </exception>
		/// <exception cref="System.InvalidOperationException">
		/// The <see cref="HtmlWriter"/> is not in a state that allows writing attributes.
		/// </exception>
		/// <exception cref="System.ObjectDisposedException">
		/// The <see cref="HtmlWriter"/> has been disposed.
		/// </exception>
		public void WriteAttributeName (HtmlAttributeId id)
		{
			if (id == HtmlAttributeId.Unknown)
				throw new ArgumentException ("Invalid attribute.", "id");

			if (WriterState == HtmlWriterState.Default)
				throw new InvalidOperationException ("Cannot write attributes in the Default state.");

			CheckDisposed ();

			EncodeAttributeName (id.ToString ());
		}
Beispiel #5
0
		/// <summary>
		/// Write the attribute to the output stream.
		/// </summary>
		/// <remarks>
		/// Writes the attribute to the output stream.
		/// </remarks>
		/// <param name="id">The attribute identifier.</param>
		/// <param name="value">The attribute value.</param>
		/// <exception cref="System.ArgumentException">
		/// <paramref name="id"/> is not a valid HTML attribute identifier.
		/// </exception>
		/// <exception cref="System.ArgumentNullException">
		/// <paramref name="value"/> is <c>null</c>.
		/// </exception>
		/// <exception cref="System.InvalidOperationException">
		/// The <see cref="HtmlWriter"/> is not in a state that allows writing attributes.
		/// </exception>
		/// <exception cref="System.ObjectDisposedException">
		/// The <see cref="HtmlWriter"/> has been disposed.
		/// </exception>
		public void WriteAttribute (HtmlAttributeId id, string value)
		{
			if (id == HtmlAttributeId.Unknown)
				throw new ArgumentException ("Invalid attribute.", "id");

			if (value == null)
				throw new ArgumentNullException ("value");

			CheckDisposed ();

			EncodeAttribute (id.ToAttributeName (), value);
		}
Beispiel #6
0
		/// <summary>
		/// Write the attribute to the output stream.
		/// </summary>
		/// <remarks>
		/// Writes the attribute to the output stream.
		/// </remarks>
		/// <param name="id">The attribute identifier.</param>
		/// <param name="buffer">A buffer containing the attribute value.</param>
		/// <param name="index">The starting index of the attribute value.</param>
		/// <param name="count">The number of characters in the attribute value.</param>
		/// <exception cref="System.ArgumentException">
		/// <paramref name="id"/> is not a valid HTML attribute identifier.
		/// </exception>
		/// <exception cref="System.ArgumentNullException">
		/// <paramref name="buffer"/> is <c>null</c>.
		/// </exception>
		/// <exception cref="System.ArgumentOutOfRangeException">
		/// <para><paramref name="index"/> is less than zero or greater than the length of
		/// <paramref name="buffer"/>.</para>
		/// <para>-or-</para>
		/// <para><paramref name="index"/> and <paramref name="count"/> do not specify
		/// a valid range in the <paramref name="buffer"/>.</para>
		/// </exception>
		/// <exception cref="System.InvalidOperationException">
		/// The <see cref="HtmlWriter"/> is not in a state that allows writing attributes.
		/// </exception>
		/// <exception cref="System.ObjectDisposedException">
		/// The <see cref="HtmlWriter"/> has been disposed.
		/// </exception>
		public void WriteAttribute (HtmlAttributeId id, char[] buffer, int index, int count)
		{
			if (id == HtmlAttributeId.Unknown)
				throw new ArgumentException ("Invalid attribute.", "id");

			ValidateArguments (buffer, index, count);

			CheckDisposed ();

			EncodeAttribute (id.ToAttributeName (), buffer, index, count);
		}
        protected OwaSafeHtmlOutboundCallbacks.TypeOfUrl GetTypeOfUrl(string urlString, HtmlAttributeId htmlAttrId)
        {
            if (string.IsNullOrEmpty(urlString))
            {
                return(OwaSafeHtmlOutboundCallbacks.TypeOfUrl.Unknown);
            }
            if (urlString.StartsWith(OwaSafeHtmlCallbackBase.LocalUrlPrefix, StringComparison.Ordinal))
            {
                return(OwaSafeHtmlOutboundCallbacks.TypeOfUrl.Local);
            }
            Uri uri;

            if (null == (uri = Utilities.TryParseUri(urlString)))
            {
                return(OwaSafeHtmlOutboundCallbacks.TypeOfUrl.Unknown);
            }
            string scheme = uri.Scheme;

            if (string.IsNullOrEmpty(scheme))
            {
                return(OwaSafeHtmlOutboundCallbacks.TypeOfUrl.Unknown);
            }
            if (CultureInfo.InvariantCulture.CompareInfo.Compare(scheme, "file", CompareOptions.IgnoreCase) == 0 && htmlAttrId == HtmlAttributeId.Href)
            {
                return(OwaSafeHtmlOutboundCallbacks.TypeOfUrl.Redirection);
            }
            for (int i = 0; i < OwaSafeHtmlOutboundCallbacks.RedirProtocols.Length; i++)
            {
                if (CultureInfo.InvariantCulture.CompareInfo.Compare(scheme, OwaSafeHtmlOutboundCallbacks.RedirProtocols[i], CompareOptions.IgnoreCase) == 0)
                {
                    if (CultureInfo.InvariantCulture.CompareInfo.Compare(scheme, "mailto", CompareOptions.IgnoreCase) == 0 && htmlAttrId == HtmlAttributeId.Href)
                    {
                        this.hasFoundMailToUrlInCurrentPass = true;
                    }
                    return(OwaSafeHtmlOutboundCallbacks.TypeOfUrl.Redirection);
                }
            }
            return(OwaSafeHtmlOutboundCallbacks.TypeOfUrl.Trusted);
        }
Beispiel #8
0
 /// <summary>
 /// Converts the enum value into the equivalent attribute name.
 /// </summary>
 /// <remarks>
 /// Converts the enum value into the equivalent attribute name.
 /// </remarks>
 /// <returns>The attribute name.</returns>
 /// <param name="value">The enum value.</param>
 public static string ToAttributeName(this HtmlAttributeId value)
 {
     return(s_attrIdsToStrings[value]);
 }
Beispiel #9
0
 internal static bool IsSafeUrl(string urlString, HtmlAttributeId htmlAttr)
 {
     HtmlBodyCallback.TypeOfUrl typeOfUrl = HtmlBodyCallback.GetTypeOfUrl(urlString, htmlAttr);
     return(typeOfUrl != HtmlBodyCallback.TypeOfUrl.Unknown);
 }