Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different behavior in 2.6.2 vs 2.5.0 for ErrorAction.MaintainTokens #148

Closed
nikita-starostin opened this issue Mar 29, 2021 · 2 comments
Closed

Comments

@nikita-starostin
Copy link

Hi,

in the past I had to parse an html string where CSS-styles had been inlined, e.g.

<style>
    .className {

     }
</style>
<body>
{propertyName}
</body>

In 2.5.0 I have used next snippet to support { for CSS-styles.and tokens at same time:

        private static string PrepareHtml(string template, object values)
        {
            var substitutions = new[] { values };
            var smart = Smart.CreateDefaultSmartFormat();
            smart.Settings.ParseErrorAction = ErrorAction.MaintainTokens;
            smart.Settings.FormatErrorAction = ErrorAction.MaintainTokens;

            return smart.Format(template, substitutions);
        }

The behavior for PrepareHtml is different for 2.6.2 and 2.5.0

// 2.6.2
PrepareHtml("    .p1 { asd }    \r\n<P class=\"p1 ft3\">First Name: <SPAN class=\"ft0\">{info.firstName}</SPAN></P>", new object[] {new { info = new { firstName = "Zz" }}}); 
=>     .p1 { asd }    \r\n<P class=\"p1 ft3\">First Name: <SPAN class=\"ft0\">{info.firstName}</SPAN></P>

// 2.5.0
PrepareHtml("    .p1 { asd }    \r\n<P class=\"p1 ft3\">First Name: <SPAN class=\"ft0\">{info.firstName}</SPAN></P>", new object[] {new { info = new { firstName = "Zz" }}}); 
=>     .p1 { asd }    \r\n<P class=\"p1 ft3\">First Name: <SPAN class=\"ft0\">Zz</SPAN></P>

not sure is it a bug, or not, for desired behavior I have rollbacked to 2.5.0

@axunonb
Copy link
Member

axunonb commented Mar 29, 2021

Hi
Just had a look, but I cannot reproduce your result for v2.5.0:

SmartFormat, Version=2.5.0.0, Culture=neutral, PublicKeyToken=568866805651201f
My result:

    .p1 { asd }
<P class="p1 ft3">First Name: <SPAN class="ft0">{info.firstName}</SPAN></P>

SmartFormat, Version=2.6.2.0, Culture=neutral, PublicKeyToken=568866805651201f
My result:

    .p1 { asd }
<P class="p1 ft3">First Name: <SPAN class="ft0">{info.firstName}</SPAN></P>

A complete sample, which could be run in a unit test would be helpful.

Parsing HTML works fine, except - like in your case - when it includes CSS styles and JavaScript. Both have curly braces in their syntax, which Smart.Format interprets as { placeholders }.

axunonb added a commit that referenced this issue Apr 2, 2021
axunonb added a commit that referenced this issue Apr 2, 2021
@axunonb
Copy link
Member

axunonb commented Apr 2, 2021

Verified as a bug, will be closed by PR #149 - see PR comments for details

@axunonb axunonb closed this as completed Apr 2, 2021
axunonb added a commit that referenced this issue Apr 9, 2021
* Reference to issues #148, #147, #143

* Reference to issues #148, #147, #143

* Updated README.md

* Fix for #149 (comment)
axunonb added a commit that referenced this issue Apr 10, 2021
* Reference to issues #148, #147, #143
* Updated README.md
* Fix for #149 (comment)
* Update CHANGES.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants