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

Interweave SSR breaks if style attribute malformed #268

Open
AlexHarmsworth opened this issue Mar 5, 2024 · 0 comments
Open

Interweave SSR breaks if style attribute malformed #268

AlexHarmsworth opened this issue Mar 5, 2024 · 0 comments

Comments

@AlexHarmsworth
Copy link

AlexHarmsworth commented Mar 5, 2024

There have been instances where an author has managed to copy and paste inline styling from Word into our CMS, which then breaks Interweave SSR.

We are fixing this by sanitising pasted content in our CMS, but thought it might be worth documenting in case someone also runs into the following error:

SyntaxError: /([^;])+/i
    at Object.module.exports [as default] (webpack://[REPO]/./node_modules/style-parser/index.js?:36:11)
    at createStyleDeclaration (webpack://[REPO]/./node_modules/interweave-ssr/lib/index.js?:61:45)
    at Object.createElement (webpack://[REPO]/./node_modules/interweave-ssr/lib/index.js?:117:23)
    at Parser._insertElement (webpack://[REPO]/./node_modules/parse5/lib/parser/index.js?:559:42)
    at bStartTagInBody (webpack://[REPO]/./node_modules/parse5/lib/parser/index.js?:1481:7)
    at Object.startTagInBody [as START_TAG_TOKEN] (webpack://[REPO]/./node_modules/parse5/lib/parser/index.js?:1702:17)
    at Parser._processToken (webpack://[REPO]/./node_modules/parse5/lib/parser/index.js?:657:55)
    at Parser._processInputToken (webpack://[REPO]/./node_modules/parse5/lib/parser/index.js?:684:18)
    at Parser._runParsingLoop (webpack://[REPO]/./node_modules/parse5/lib/parser/index.js?:440:18)
    at Parser.parse (webpack://[REPO]/./node_modules/parse5/lib/parser/index.js?:344:14)
    at Object.parse (webpack://[REPO]/./node_modules/parse5/lib/index.js?:10:19)
    at parseHTML (webpack://[REPO]/./node_modules/interweave-ssr/lib/index.js?:140:17)
    at Object.set (webpack://[REPO]/./node_modules/interweave-ssr/lib/index.js?:158:50)
    at Parser.createContainer (webpack://[REPO]/./app/javascript/packs/server-bundle.ts_+_1359_modules?:19718:20)
    at new Parser (webpack://[REPO]/./app/javascript/packs/server-bundle.ts_+_1359_modules?:19521:27)
    at esm_Markup (webpack://[REPO]/./app/javascript/packs/server-bundle.ts_+_1359_modules?:20072:18) 

This error is triggered when Interweave SSR tries to parse the inline styles, and one of the styles has a property but no value:

<p><em style="border: 0px solid rgb(229, 231, 235); color: ;"><b>I'm pasted from Word but missing the color value</b></em></p>

It would be ideal if we could handle the SyntaxError thrown in createStyleDeclaration in situations like this, so it fails more gracefully. For example, skipping the offending property and logging a warning.

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