Skip to content

Commit

Permalink
chore(macros/EmbedLiveSample): deprecate parameters 4 to 6 (#6299)
Browse files Browse the repository at this point in the history
Co-authored-by: Claas Augner <[email protected]>
  • Loading branch information
teoli2003 and caugner authored Sep 6, 2022
1 parent a0fd003 commit c4197f3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 213 deletions.
14 changes: 11 additions & 3 deletions kumascript/macros/EmbedLiveSample.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,22 @@
// $1 - The width of the iframe (optional)
// $2 - The height of the iframe (optional)
// $3 - The url of a screenshot of the sample working as intended (optional)
// $4 - The slug from which to load the sample (optional; current page used if not provided)
// $5 - The class name of the frame; defaults to "sample-code-frame". If you
// $4 - (Deprecated) The slug from which to load the sample (optional; current page used if not provided)
// $5 - (Deprecated) The class name of the frame; defaults to "sample-code-frame". If you
// pass this parameter and give it a value other than "sample-code-frame",
// then the "Open in CodePen"/"Open in JSFiddle" buttons will not be displayed.
// $6 - Allowed features, separated by semicolons (optional)
// $6 - (Deprecated) Allowed features, separated by semicolons (optional)
//
// See also : LiveSampleLink
// We have deprecated the use of the $4 to $6 parameters
// If one of this parameter is not empty, we raise a MacroDeprecationError flaw
// When there will be 0 use left on translated-content (May 2022: 203 occurrences for $4),
// we will be able to simplify this macro (and likely the whole of MDN).
if ($4 !== "" || $5 !== "" || $6 !== "") {
mdn.deprecated("The fourth to sixth parameters of 'EmbedLiveSample' are deprecated");
}
var sampleIdOrOffset = $0 || $token.location.start.offset;
if(typeof sampleIdOrOffset === "string"){
sampleIdOrOffset = sampleIdOrOffset.toLowerCase();
Expand Down
9 changes: 4 additions & 5 deletions kumascript/src/api/mdn.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,10 @@ module.exports = {
/**
* Throw a deprecation error.
*/
deprecated() {
this.env.recordNonFatalError(
"deprecated",
"This macro has been deprecated, and should be removed."
);
deprecated(
message = "This macro has been deprecated, and should be removed."
) {
this.env.recordNonFatalError("deprecated", message);
},

async fetchWebExtExamples() {
Expand Down
207 changes: 2 additions & 205 deletions kumascript/tests/macros/EmbedLiveSample.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
*/
const { assert, itMacro, describeMacro, beforeEachMacro } = require("./utils");

// This needs to match what the equivalent is inside the EmbedLiveSample.ejs file.
// Duplicating it here to avoid hardcoding its number in multiple places.
const MIN_HEIGHT = 60;

describeMacro("EmbedLiveSample", function () {
beforeEachMacro(function (macro) {
macro.ctx.env.live_samples = {
Expand Down Expand Up @@ -148,217 +144,18 @@ describeMacro("EmbedLiveSample", function () {
"</iframe>"
);
});
itMacro('Four arguments: ID, width, height, ""', function (macro) {
macro.ctx.env.url = "/en-US/docs/Web/CSS/::before";
return assert.eventually.equal(
macro.call("Adding_quotation_marks", "500", "50", ""),
'<iframe class="sample-code-frame"' +
' title="Adding quotation marks sample"' +
' id="frame_adding_quotation_marks"' +
` width="500" height="${MIN_HEIGHT}"` +
' src="https://mdn.mozillademos.org/en-US/docs/Web/CSS/::before/_sample_.adding_quotation_marks.html">' +
"</iframe>"
);
});
itMacro("Four arguments: ID, width, height, screenshot", function (macro) {
macro.ctx.env.url = "/en-US/docs/Web/SVG/Tutorial/Gradients";
return assert.eventually.equal(
macro.call(
"SVGLinearGradient",
"120",
"240",
"/files/722/SVG_Linear_Gradient_Example.png"
),
'<table class="sample-code-table"><thead><tr>' +
'<th scope="col" style="text-align: center;">Screenshot</th>' +
'<th scope="col" style="text-align: center;">Live sample</th>' +
"</tr></thead>" +
"<tbody><tr><td>" +
'<img alt="" class="internal" src="/files/722/SVG_Linear_Gradient_Example.png" />' +
"</td><td>" +
'<iframe class="sample-code-frame"' +
' title="SVGLinearGradient sample"' +
' id="frame_svglineargradient"' +
' width="120" height="240"' +
' src="https://mdn.mozillademos.org/en-US/docs/Web/SVG/Tutorial/Gradients/_sample_.svglineargradient.html">' +
"</iframe></td></tr></tbody></table>"
);
});
itMacro(
"Four arguments: ID, width, height, XSS attempt (failed)",
function (macro) {
macro.ctx.env.url = "/en-US/docs/Web/SVG/Tutorial/Gradients";
return assert.eventually.equal(
macro.call(
"SVGLinearGradient",
"120",
"240",
'"><script>alert("XSS");</script>'
),
'<table class="sample-code-table"><thead><tr>' +
'<th scope="col" style="text-align: center;">Screenshot</th>' +
'<th scope="col" style="text-align: center;">Live sample</th>' +
"</tr></thead>" +
"<tbody><tr><td>" +
'<img alt="" class="internal" src="&#34;&gt;&lt;script&gt;alert(&#34;XSS&#34;);&lt;/script&gt;" />' +
"</td><td>" +
'<iframe class="sample-code-frame"' +
' title="SVGLinearGradient sample"' +
' id="frame_svglineargradient"' +
' width="120" height="240"' +
' src="https://mdn.mozillademos.org/en-US/docs/Web/SVG/Tutorial/Gradients/_sample_.svglineargradient.html">' +
"</iframe></td></tr></tbody></table>"
);
}
);
const same_slug_iframe =
'<iframe class="sample-code-frame"' +
' title="Examples sample"' +
' id="frame_examples"' +
' width="700px" height="700px"' +
' src="https://mdn.mozillademos.org/en-US/docs/Web/CSS/flex-wrap/_sample_.examples.html">' +
"</iframe>";
itMacro('Five arguments: ID, width, height, "", same slug', function (macro) {
itMacro("Three arguments: ID, width, height (same slug)", function (macro) {
macro.ctx.env.url = "/en-US/docs/Web/CSS/flex-wrap";
return assert.eventually.equal(
macro.call("Examples", "700px", "700px", "", "Web/CSS/flex-wrap"),
macro.call("Examples", "700px", "700px"),
same_slug_iframe
);
});
itMacro(
"Three arguments: ID, width, height (same as Five arg, same slug)",
function (macro) {
macro.ctx.env.url = "/en-US/docs/Web/CSS/flex-wrap";
return assert.eventually.equal(
macro.call("Examples", "700px", "700px"),
same_slug_iframe
);
}
);
itMacro('Five arguments: ID, "", "", "", other slug', function (macro) {
macro.ctx.env.url = "/en-US/docs/Web/Events/focus";
return assert.eventually.equal(
macro.call("Event delegation", "", "", "", "Web/Events/blur"),
'<iframe class="sample-code-frame"' +
' title="Event delegation sample"' +
' id="frame_event_delegation"' +
' src="https://mdn.mozillademos.org/en-US/docs/Web/Events/blur/_sample_.event_delegation.html">' +
"</iframe>"
);
});
itMacro(
'Five arguments: ID, "", "", "", other non-existent slug',
async function (macro) {
macro.ctx.env.url = "/en-US/docs/Web/Events/focus";
macro.ctx.info.cleanURL = jest.fn((url) => url.toLowerCase());
macro.ctx.info.hasPage = jest.fn(() => false);
await expect(
macro.call("Event delegation", "", "", "", "Web/Events/blur")
).rejects.toThrow(
"/en-us/docs/web/events/focus references /en-us/docs/web/events/blur, which does not exist"
);
}
);
itMacro(
'Five arguments: ID, "", "", "", XSS Attempt (failed)',
function (macro) {
macro.ctx.env.url = "/en-US/docs/Web/Events/focus";
return assert.eventually.equal(
macro.call(
"Event_delegation",
"",
"",
"",
'"><script>alert("XSS");</script>'
),
'<iframe class="sample-code-frame"' +
' title="Event delegation sample"' +
' id="frame_event_delegation"' +
' src="https://mdn.mozillademos.org/en-US/docs/%22%3E%3Cscript%3Ealert(%22XSS%22);%3C/script%3E/_sample_.event_delegation.html">' +
"</iframe>"
);
}
);
itMacro('Six arguments: ID, width, height, "", "", class', function (macro) {
macro.ctx.env.url = "/en-US/docs/Web/CSS/-moz-appearance";
return assert.eventually.equal(
macro.call("sampleNone", 100, 50, "", "", "nobutton"),
'<iframe class="nobutton"' +
' title="sampleNone sample"' +
' id="frame_samplenone"' +
` width="100" height="${MIN_HEIGHT}"` +
' src="https://mdn.mozillademos.org/en-US/docs/Web/CSS/-moz-appearance/_sample_.samplenone.html">' +
"</iframe>"
);
});
itMacro(
'Six arguments: ID, width, height, "", "", XSS attempt (failed)',
function (macro) {
macro.ctx.env.url = "/en-US/docs/Web/CSS/-moz-appearance";
return assert.eventually.equal(
macro.call(
"sampleNone",
100,
50,
"",
"",
'"><script>alert("XSS");</script>'
),
'<iframe class="&#34;&gt;&lt;script&gt;alert(&#34;XSS&#34;);&lt;/script&gt;"' +
' title="sampleNone sample"' +
' id="frame_samplenone"' +
` width="100" height="${MIN_HEIGHT}"` +
' src="https://mdn.mozillademos.org/en-US/docs/Web/CSS/-moz-appearance/_sample_.samplenone.html">' +
"</iframe>"
);
}
);
itMacro(
'Seven arguments: ID, width, height, "", "", "", features',
function (macro) {
macro.ctx.env.url = "/en-US/docs/Web/API/Media_Streams_API/Constraints";
return assert.eventually.equal(
macro.call(
"Example_Constraint_exerciser",
650,
800,
"",
"",
"",
"video; microphone"
),
'<iframe class="sample-code-frame"' +
' title="Example Constraint exerciser sample"' +
' id="frame_example_constraint_exerciser"' +
' width="650" height="800"' +
' src="https://mdn.mozillademos.org/en-US/docs/Web/API/Media_Streams_API/Constraints/_sample_.example_constraint_exerciser.html"' +
' allow="video; microphone">' +
"</iframe>"
);
}
);
itMacro(
'Seven arguments: ID, width, height, "", "", "", XSS Attempt (failed)',
function (macro) {
macro.ctx.env.url = "/en-US/docs/Web/API/Media_Streams_API/Constraints";
return assert.eventually.equal(
macro.call(
"Example_Constraint_exerciser",
650,
800,
"",
"",
"",
'"><script>alert("XSS");</script>'
),
'<iframe class="sample-code-frame"' +
' title="Example Constraint exerciser sample"' +
' id="frame_example_constraint_exerciser"' +
' width="650" height="800"' +
' src="https://mdn.mozillademos.org/en-US/docs/Web/API/Media_Streams_API/Constraints/_sample_.example_constraint_exerciser.html"' +
' allow="&#34;&gt;&lt;script&gt;alert(&#34;XSS&#34;);&lt;/script&gt;">' +
"</iframe>"
);
}
);
});

0 comments on commit c4197f3

Please sign in to comment.