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

Inconsistent HTML entity decoding in attributes #3434

Open
ppena-LiveData opened this issue May 14, 2024 · 1 comment
Open

Inconsistent HTML entity decoding in attributes #3434

ppena-LiveData opened this issue May 14, 2024 · 1 comment

Comments

@ppena-LiveData
Copy link

Description:

If a template has an HTML element attribute with just a static string, then HTML entities are decoded, but if there's a mustache in the attribute, then the HTML entities are not decoded. For example, attr="&" will have & decoded to &, but attr="&{{''}}" will not have it decoded, see that example in the Ractive Playground.

Versions affected:

Maybe all? The problem is in src/parse/converters/element/readAttribute.js, since it only calls decodeCharacterReferences() when value.length === 1 && isString(value[0]).

Platforms affected:

All.

Suggested fix:

Instead of this:

  if (value.length === 1 && isString(value[0])) {
    return decodeCharacterReferences(value[0]);
  }

The code could decode all static strings, like this (thanks @GabeSchaffer for this suggested fix):

  // decode HTML entities for each static string within an attribute
  for (var i in value) {
    if (isString(value[i])) {
      value[i] = decodeCharacterReferences(value[i]);
    }
  }

  if (value.length === 1 && isString(value[0])) {
    return value[0];
  }
@evs-chris
Copy link
Contributor

Thanks for the concise bug report with a very good breakdown of the problem and resolution! This should be resolved in 1.4.4.

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