Skip to content
This repository was archived by the owner on Jun 21, 2022. It is now read-only.

Conversation

@a2sheppy
Copy link
Contributor

The SectionOnPage macro produces corrupt HTML if the title of the page includes angle
brackets. This patch fixes that; it also adds support for a third parameter that lets
you specify the name of an element to wrap the title in (optional).

@a2sheppy
Copy link
Contributor Author

Do not merge this. I just realized what a horrible mistake it is to let you specify the name of the element to wrap in in a parameter. I'll fix this in a minute.

@a2sheppy
Copy link
Contributor Author

That should fix the problem with the tags; it now only allows a given set of tags (code and kbd at the moment).

Copy link
Member

@Elchi3 Elchi3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nits that would be nice to address, otherwise r+

I verified this on https://developer.mozilla.org/en-US/docs/Web/HTML/Applying_color#Keywords

I did not test the other 70 pages which make use of this macro.

// $2 Element name to wrap the page title (not the section name) in;
// leave blank or don't specify this parameter to not wrap the title.
// Don't include the angle brackets! Only specific tags are permitted;
// they're in the allowedWrappers array.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding docs about this parameter. I think it is also a good idea to add a sample call:

// Example call
// {{SectionOnPage("/en-US/docs/Web/CSS/color_value", "Color keywords", "code")}}

var text = "";
var page = wiki.getPage($0);
var title = page.title;
var title = kuma.htmlEscape(page.title);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a page doesn't exist, this will output "SectionName in undefined". Not sure if we want to do something about it.

elem = elem.toLowerCase();
if (allowedWrappers.includes(elem)) {
title = `<${elem}>${title}</${elem}>`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: semicolon at the end. (thanks for using template literals!).

The SectionOnPage macro produces corrupt HTML if the title of the page includes angle
brackets. This patch fixes that; it also adds support for a third parameter that lets
you specify the name of an element to wrap the title in (optional).
var summary = (page && page.summary) ? mdn.escapeQuotes(page.summary) :
localize(commonLocalStrings, "summary");
if (!title || title == undefined || title == "undefined") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you want if (title === undefined) here.

title == "undefined" looks like you wanted to actually write typeof title === "undefined", which I think isn't needed as the title variable has been declared, so there is no risk of a ReferenceError here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I do in fact mean title == "undefined" here. Turns out kuma.htmlEscape(page.title) returns the string "undefined" if the page doesn't exist.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OMG

@Elchi3 Elchi3 merged commit 04473ba into mdn:master Oct 12, 2017
jwhitlock added a commit to jwhitlock/kuma that referenced this pull request Oct 16, 2017
Add updated translations for:
* es-MX - Spanish (Mexico)
* ka - Georgian
* te - Telegu

Add kumascript PRs:
* mdn/kumascript#320 - L10n:Common, SectionOnPage: Fix escaping
* mdn/kumascript#346 - Push tagged images to quay.io
* mdn/kumascript#352 - SpecName, spec2: Add Visual Viewport API
* mdn/kumascript#353 - LegacyAddonsNotice: Add French
* mdn/kumascript#354 - JsSidebar: Add Client-side web APIs
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants