Skip to content

Commit

Permalink
fix(storefront): Clear invalid UTF-8 chars on CMS content frontmatter
Browse files Browse the repository at this point in the history
  • Loading branch information
leomp12 committed Jan 17, 2025
1 parent a5a1b13 commit e3d95af
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/storefront/config/storefront.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ export default () => {
config.set({ storeId: Number(ECOM_STORE_ID) });
}

const parseFrontmatter = (markdown) => {
const parseFrontmatter = (_markdown) => {
let markdown = '';
for (let i = 0; i < _markdown.length; i++) {
// Clear invalid UTF-8 chars
const charCode = _markdown.charCodeAt(i);
if (charCode >= 128 && charCode <= 159) continue;
if (charCode >= 636) continue;
markdown += _markdown.charAt(i);
}
let matter = {};
if (markdown.substring(0, 4) === '---\n') {
const [frontmatter, _md] = markdown.substring(4).split('\n---\n');
Expand Down

0 comments on commit e3d95af

Please sign in to comment.