telerik / kendo-ui-core

An HTML5, jQuery-based widget library for building modern web apps.
http://www.telerik.com/kendo-ui
Other
2.54k stars 1.91k forks source link

Quotes in the HtmlAttributes configuration option cannot be applied for the Grid's columns #7101

Closed alestoya closed 1 year ago

alestoya commented 1 year ago

Bug report

Reproduction of the problem

Current behavior

Having a grid with a similar column setup will result in an error.

.Columns(columns =>
{
    columns.Bound(p => p.UnitsInStock).HtmlAttributes(new { @class = "#: UnitsInStock == 39 ? 'test' : 'a' #" });
})

Expected/desired behavior

Having a grid with a similar column setup should not result in an error.

.Columns(columns =>
{
    columns.Bound(p => p.UnitsInStock).HtmlAttributes(new { @class = "#: UnitsInStock == 39 ? 'test' : 'a' #" });
})

Environment

aleksandarevangelatov commented 1 year ago

Single quotes are not valid characters for HTML 5 attributes - https://www.w3.org/TR/2011/WD-html5-20110525/syntax.html#attributes-0 - "Attribute names must consist of one or more characters other than the space characters, U+0000 NULL, U+0022 QUOTATION MARK ("), U+0027 APOSTROPHE ('), U+003E GREATER-THAN SIGN (>), U+002F SOLIDUS (/), and U+003D EQUALS SIGN (=) characters, the control characters, and any characters that are not defined by Unicode."

If quotes should be present in the attributes the correct syntax would be:

.Columns(columns =>
    {
        columns.Bound(p => p.UnitsInStock).HtmlAttributes(new { @class = "#= UnitsInStock == 39 ? `\"test\"` : `\"a\"` #" });
    })

Updated Telerik REPL example

ogorodnikovInfopulse commented 1 year ago

Original bug was not related to single quotes but to french letters. Ticket number 1584947

var arr = new char[]{(char)68, (char)233, (char)116, (char)97, (char)105, (char)108 }; var strCreated = new string(arr); //"Détail" - get from localization from french x.Template(string.Empty) .HtmlAttributes(new {title = strCreated});

aleksandarevangelatov commented 1 year ago

With the fix, the HtmlAttributes, HeaderHtmlAttributes and FooterHtmlAttributes methods will accept an additional optional Boolean parameter that would indicate whether the attributes should be encoded or not. By default, the attributes passed are encoded using the default HTML encoder.

The following configuration will NOT encode the passed attributes:

.Columns(columns =>
    {
        columns.Bound(p => p.UnitsInStock).HtmlAttributes(new {title = "Détail"}, false);
    })