-
-
Notifications
You must be signed in to change notification settings - Fork 11.5k
🐛 Fixed silent importer failures and non-error rejections #27651
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
Open
envsecure
wants to merge
5
commits into
TryGhost:main
Choose a base branch
from
envsecure:fix-silent-importer-failures
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
03d1313
🐛 Fixed non-error rejection in DataImporter
envsecure 143bd65
✨ Included error message in import completion email
envsecure e641460
♻️ Restored original HTML structure to email template and included er…
envsecure 9840570
🛡️ Hardened error handling in email template
envsecure 0873fb9
fix: add HTML sanitization and robust error handling to email template
envsecure File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
177 changes: 17 additions & 160 deletions
177
ghost/core/core/server/data/importer/email-template.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,163 +1,20 @@ | ||
| module.exports = ({result, siteUrl, postsUrl, emailRecipient}) => ` | ||
| <!doctype html> | ||
| <html> | ||
| <head> | ||
| <meta name="viewport" content="width=device-width"> | ||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | ||
| <title>Your content import is complete</title> | ||
| <style> | ||
| /* ------------------------------------- | ||
| RESPONSIVE AND MOBILE FRIENDLY STYLES | ||
| ------------------------------------- */ | ||
| @media only screen and (max-width: 620px) { | ||
| table[class=body] h1 { | ||
| font-size: 28px !important; | ||
| margin-bottom: 10px !important; | ||
| } | ||
| table[class=body] p, | ||
| table[class=body] ul, | ||
| table[class=body] ol, | ||
| table[class=body] td, | ||
| table[class=body] span, | ||
| table[class=body] a { | ||
| font-size: 16px !important; | ||
| } | ||
| table[class=body] .title { | ||
| font-size: 22px !important; | ||
| } | ||
| table[class=body] .wrapper, | ||
| table[class=body] .article { | ||
| padding: 10px !important; | ||
| } | ||
| table[class=body] .content { | ||
| padding: 0 !important; | ||
| } | ||
| table[class=body] .container { | ||
| padding: 0 !important; | ||
| width: 100% !important; | ||
| } | ||
| table[class=body] .main { | ||
| border-left-width: 0 !important; | ||
| border-radius: 0 !important; | ||
| border-right-width: 0 !important; | ||
| } | ||
| table[class=body] .btn table { | ||
| width: 100% !important; | ||
| } | ||
| table[class=body] .btn a { | ||
| width: 100% !important; | ||
| } | ||
| table[class=body] .img-responsive { | ||
| height: auto !important; | ||
| max-width: 100% !important; | ||
| width: auto !important; | ||
| } | ||
| table[class=body] p[class=small], | ||
| table[class=body] a[class=small] { | ||
| font-size: 12x !important; | ||
| } | ||
| ${(() => { | ||
| const escapeHtml = (unsafe) => (unsafe || '').toString() | ||
| .replace(/&/g, '&') | ||
| .replace(/</g, '<') | ||
| .replace(/>/g, '>') | ||
| .replace(/"/g, '"') | ||
| .replace(/'/g, '''); | ||
| const errors = result?.data?.errors; | ||
| const hasErrors = errors && Array.isArray(errors) && errors.length > 0; | ||
| if (hasErrors) { | ||
| const msg = errors[0].message || errors[0].toString() || 'Unknown error'; | ||
| return `Import unsuccessful: ${escapeHtml(msg)}`; | ||
| } | ||
| /* ------------------------------------- | ||
| PRESERVE THESE STYLES IN THE HEAD | ||
| ------------------------------------- */ | ||
| @media all { | ||
| .ExternalClass { | ||
| width: 100%; | ||
| } | ||
| .ExternalClass, | ||
| .ExternalClass p, | ||
| .ExternalClass span, | ||
| .ExternalClass font, | ||
| .ExternalClass td, | ||
| .ExternalClass div { | ||
| line-height: 100%; | ||
| } | ||
| .recipient-link a { | ||
| color: inherit !important; | ||
| font-family: inherit !important; | ||
| font-size: inherit !important; | ||
| font-weight: inherit !important; | ||
| line-height: inherit !important; | ||
| text-decoration: none !important; | ||
| } | ||
| #MessageViewBody a { | ||
| color: inherit; | ||
| text-decoration: none; | ||
| font-size: inherit; | ||
| font-family: inherit; | ||
| font-weight: inherit; | ||
| line-height: inherit; | ||
| } | ||
| } | ||
| hr { | ||
| border-width: 0; | ||
| height: 0; | ||
| margin-top: 34px; | ||
| margin-bottom: 34px; | ||
| border-bottom-width: 1px; | ||
| border-bottom-color: #EEF5F8; | ||
| } | ||
| a { | ||
| color: #3A464C; | ||
| } | ||
| </style> | ||
| </head> | ||
| <body class="" style="background-color: #ffffff; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; -webkit-font-smoothing: antialiased; font-size: 14px; line-height: 1.5em; margin: 0; padding: 0; -ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%;"> | ||
| <table border="0" cellpadding="0" cellspacing="0" class="body" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;"> | ||
| <tr> | ||
| <td style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 14px; vertical-align: top;"> </td> | ||
| <td class="container" style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 14px; vertical-align: top; display: block; Margin: 0 auto; max-width: 540px; padding: 10px; width: 540px;"> | ||
| <div class="content" style="box-sizing: border-box; display: block; Margin: 0 auto; max-width: 600px; padding: 30px 20px;"> | ||
|
|
||
| <!-- START CENTERED CONTAINER --> | ||
| <span class="preheader" style="color: transparent; display: none; height: 0; max-height: 0; max-width: 0; opacity: 0; overflow: hidden; mso-hide: all; visibility: hidden; width: 0;">Your content import is complete</span> | ||
| <table class="main" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%; background: #ffffff; border-radius: 8px;"> | ||
|
|
||
| <!-- START MAIN CONTENT AREA --> | ||
| <tr> | ||
| <td class="wrapper" style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 14px; vertical-align: top; box-sizing: border-box;"> | ||
| <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;"> | ||
| <tr> | ||
| <td align="center" style="padding-top: 20px; padding-bottom: 12px;"><img src="https://static.ghost.org/v4.0.0/images/ghost-orb-4.png" width="60" height="60" style="width: 60px; height: 60px;" /></td> | ||
| </tr> | ||
| <tr> | ||
| <td style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; vertical-align: top;"> | ||
| <p class="title" style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 21px; color: #3A464C; font-weight: normal; line-height: 25px; margin-bottom: 30px; margin-top: 50px; font-weight: 600; color: #15212A;">${result?.data?.errors ? 'Import unsuccessful' : 'Your content import has finished successfully'}</p> | ||
| </td> | ||
| </tr> | ||
| ${result?.data?.errors ? ` | ||
| <tr> | ||
| <td style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 14px; vertical-align: top; padding-bottom: 16px;">One or more error occured while importing your content. Please contact support or report on the <a href="https://forum.ghost.org/">Ghost Community Forum</a>.</td> | ||
| </tr> | ||
| ` : ` | ||
| <tr> | ||
| <td style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 14px; vertical-align: top; padding-bottom: 12px; padding-top: 16px;"> | ||
| <a href="${postsUrl.href}" target="_blank" style="display: inline-block; color: #ffffff; background-color: #15212A; border: solid 1px #15212A; border-radius: 5px; box-sizing: border-box; cursor: pointer; text-decoration: none; font-size: 16px; font-weight: normal; margin: 0; padding: 9px 22px 10px; border-color: #15212A;">View posts</a> | ||
| </td> | ||
| </tr> | ||
| `} | ||
| </table> | ||
| </td> | ||
| </tr> | ||
| <tr> | ||
| <td style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; vertical-align: top; padding-top: 80px; padding-bottom: 10px;"> | ||
| <div class="footer"> | ||
| <p class="small" style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; color: #738A94; font-weight: normal; margin: 0; line-height: 18px; margin-bottom: 0px; font-size: 11px;">This email was sent from <a href="${siteUrl.href}" style="color: #738A94;">${siteUrl.host}</a> to <a href="mailto:${emailRecipient}" style="color: #738A94;">${emailRecipient}</a></p> | ||
| </div> | ||
| </td> | ||
| </tr> | ||
|
|
||
| <!-- END MAIN CONTENT AREA --> | ||
| </table> | ||
|
|
||
| return 'Your content import has finished successfully'; | ||
| })()} | ||
|
|
||
| <!-- END CENTERED CONTAINER --> | ||
| </div> | ||
| </td> | ||
| <td style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 14px; vertical-align: top;"> </td> | ||
| </tr> | ||
| </table> | ||
| </body> | ||
| </html> | ||
| `; | ||
| [Ghost Community Forum](https://forum.ghost.org/) | ||
| [View posts](${postsUrl.href}) | ||
|
|
||
| This email was sent from [${siteUrl.host}](${siteUrl.href}) to [${emailRecipient}](mailto:${emailRecipient}) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: TryGhost/Ghost
Length of output: 579
🏁 Script executed:
cat "ghost/core/core/server/data/importer/email-template.js"Repository: TryGhost/Ghost
Length of output: 833
File is syntactically invalid—missing module.exports and template literal wrapper.
The file currently contains only a template expression and markdown strings without any surrounding module wrapper. Lines 1–20 cannot execute as valid JavaScript. The entire content must be wrapped with
module.exports = ({result, siteUrl, postsUrl, emailRecipient}) => tpl\`` at the start and ``; `` at the end to function.Proposed fix
🧰 Tools
🪛 Biome (2.4.14)
[error] 1-1: Expected a semicolon or an implicit semicolon after a statement, but found none
(parse)
[error] 17-17: expected
,but instead foundCommunity(parse)
[error] 17-17: expected
,but instead foundForum(parse)
[error] 17-17: expected
,but instead found:(parse)
[error] 18-18: expected
,but instead found[(parse)
[error] 18-18: expected
,but instead foundposts(parse)
[error] 18-18: expected
,but instead found{(parse)
[error] 18-18: expected
,but instead found.(parse)
[error] 20-20: expected
,but instead foundThis(parse)
[error] 20-20: expected
,but instead foundemail(parse)
[error] 20-20: expected
,but instead foundwas(parse)
[error] 20-20: expected
,but instead foundsent(parse)
[error] 20-20: expected
,but instead foundfrom(parse)
[error] 20-20: expected
]but instead found{(parse)
[error] 20-20: expected
,but instead found.(parse)
[error] 20-20: expected
,but instead found](parse)
[error] 20-20: Expected a statement but instead found ') to [$'.
(parse)
[error] 20-20: Expected a statement but instead found '](mailto:$'.
(parse)
[error] 20-20: Expected a statement but instead found ')'.
(parse)
🤖 Prompt for AI Agents