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

Title with html entities not properly decoded #13

Open
uuf6429 opened this issue Aug 11, 2022 · 0 comments
Open

Title with html entities not properly decoded #13

uuf6429 opened this issue Aug 11, 2022 · 0 comments

Comments

@uuf6429
Copy link

uuf6429 commented Aug 11, 2022

WordPress titles typically do not contain HTML, as far as I know, but special characters seem to be encoded as html entities (see also: https://stackoverflow.com/q/52229126/314056).

This is my solution for now:

const oldPopulateFields = wp2storyblok.populateFields;
wp2storyblok.populateFields = async function (data, component_name, mapping, taxonomies) {
  const fields = await oldPopulateFields.call(wp2storyblok, data, component_name, mapping, taxonomies);

  // note: textarea is a trick to avoid html injection, see also: https://stackoverflow.com/a/7394787/314056
  fields.name = new JSDOM(
    `<body><textarea>${fields.name}</textarea></body>`
  ).window.document.body.firstChild.value;

  return fields;
};

It uses jsdom, which I'm already using for other purposes.

Since this project uses turndown, (which in turn uses domino), maybe that could be used in place of jsdom.

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

1 participant