0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

🐛 Fixed iframe script for AMP not injected

closes #11762

- iframe embeds which include a line break were undetected by the regex which checks for the existence and injects the required amp script
- this fix updates the regex to include any non-word character, as line-breaks are not included in the general `.` token
This commit is contained in:
Aileen Nowak 2020-06-01 16:06:13 +12:00
parent 00c324fa4e
commit c779ed0bce
2 changed files with 6 additions and 4 deletions

View file

@ -24,8 +24,8 @@ function ampComponents() {
components.push('<script async custom-element="amp-anim" src="https://cdn.ampproject.org/v0/amp-anim-0.1.js"></script>');
}
let iframeCount = (html.match(/(<iframe)(.*?)(<\/iframe>)/gi) || []).length;
let youtubeCount = (html.match(/(<iframe)(.*?)(youtu.be\/|youtube(-nocookie)?.com\/(v\/|.*u\/\w\/|embed\/|.*v=))(.*?)(<\/iframe>)/gi) || []).length;
let iframeCount = (html.match(/(<iframe)(.*?\s*?)(<\/iframe>)/gi) || []).length;
let youtubeCount = (html.match(/(<iframe)(.*?\s*?)(youtu.be\/|youtube(-nocookie)?.com\/(v\/|.*u\/\w\/|embed\/|.*v=))(.*?\s*?)(<\/iframe>)/gi) || []).length;
if (youtubeCount) {
components.push('<script async custom-element="amp-youtube" src="https://cdn.ampproject.org/v0/amp-youtube-0.1.js"></script>');

View file

@ -52,8 +52,10 @@ describe('{{amp_components}} helper', function () {
it('adds scripts for youtube embeds and iframes', function () {
const post = {
html: `
<iframe src="https://www.youtube.com/embed/zqNTltOGh5c" frameborder="0"></iframe>
<iframe src="//giphy.com/embed/o0vwzuFwCGAFO" width="480" height="480" frameBorder="0" class="giphy-embed" allowFullScreen></iframe>
<iframe src="https://www.youtube.com/embed/zqNTltOGh5c" frameborder="0">
</iframe>
<iframe src="//giphy.com/embed/o0vwzuFwCGAFO" width="480" height="480" frameBorder="0" class="giphy-embed" allowFullScreen>
</iframe>
`
};