Skip to content

Commit

Permalink
Merge pull request #3834 from coralproject/hotfix/6.16.2
Browse files Browse the repository at this point in the history
- Fix terser webpack plugin memory leak (#3832)
- Fix how links are handled in comments (#3828)
- Fix flatten replies admin toggle not showing flatten replies working in stream (#3834)
  • Loading branch information
nick-funk authored Jan 6, 2022
2 parents 62252f4 + fbed435 commit 034865e
Show file tree
Hide file tree
Showing 9 changed files with 78,446 additions and 957 deletions.
79,283 changes: 78,341 additions & 942 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coralproject/talk",
"version": "6.16.1",
"version": "6.16.2",
"author": "The Coral Project",
"homepage": "https://coralproject.net/",
"sideEffects": [
Expand Down Expand Up @@ -374,7 +374,7 @@
"strip-ansi": "^6.0.0",
"style-loader": "^1.1.3",
"subscriptions-transport-ws": "^0.9.16",
"terser-webpack-plugin": "^2.3.5",
"terser-webpack-plugin": "^4.2.3",
"thread-loader": "^2.1.3",
"timekeeper": "^2.2.0",
"ts-jest": "26.3.0",
Expand Down
2 changes: 1 addition & 1 deletion src/core/build/createWebpackConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export default function createWebpackConfig(
safari10: true,
},
cache: enableBuildCache,
parallel: true,
parallel: 4,
sourceMap: !disableSourcemaps,
}),
],
Expand Down
14 changes: 8 additions & 6 deletions src/core/client/stream/local/initLocalState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ import {
} from "coral-framework/lib/relay";
import { GQLFEATURE_FLAG } from "coral-framework/schema";

import { FEATURE_FLAG } from "coral-stream/__generated__/AllCommentsTabContainer_settings.graphql";
import { initLocalStateQuery } from "coral-stream/__generated__/initLocalStateQuery.graphql";

import { COMMENTS_ORDER_BY } from "../constants";
import { AUTH_POPUP_ID, AUTH_POPUP_TYPE } from "./constants";

interface ResolvedConfig {
readonly featureFlags: FEATURE_FLAG[];
readonly featureFlags: string[];
readonly flattenReplies?: boolean | null;
}

Expand All @@ -32,7 +31,7 @@ async function resolveConfig(
return staticConfig as ResolvedConfig;
}
if (process.env.NODE_ENV === "development") {
// Send a graphql query to server during development to get the feature flags.
// Send a graphql query to server during development to get the needed settings.
// The reason is that we don't have static config during development.
const data = await fetchQuery<initLocalStateQuery>(
environment,
Expand All @@ -49,7 +48,10 @@ async function resolveConfig(

return data.settings as ResolvedConfig;
}
return { featureFlags: [] };
return {
featureFlags: [],
flattenReplies: false,
};
}

/**
Expand Down Expand Up @@ -82,7 +84,7 @@ const initLocalState: InitLocalState = async ({
...rest,
});

const { featureFlags, ...settings } = await resolveConfig(
const { featureFlags, flattenReplies } = await resolveConfig(
environment,
staticConfig
);
Expand Down Expand Up @@ -145,7 +147,7 @@ const initLocalState: InitLocalState = async ({
);

// Enable flatten replies
localRecord.setValue(!!settings.flattenReplies, "flattenReplies");
localRecord.setValue(!!flattenReplies, "flattenReplies");

// Enable z-key comment seen
localRecord.setValue(
Expand Down
5 changes: 5 additions & 0 deletions src/core/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ export interface StaticConfig {
*/
featureFlags: string[];

/**
* flattenReplies is whether or not flattenReplies is enabled on the tenant.
*/
flattenReplies: boolean;

/**
* forceAdminLocalAuth is whether local authentication is always available
* for this Coral deployment. This is useful for ensuring that Coral service
Expand Down
54 changes: 52 additions & 2 deletions src/core/common/helpers/sanitize.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,22 @@ it("sanitizes without features enabled", () => {
`);
});

it("allows mailto links", () => {
const sanitize = createSanitize(window as any);
expect(sanitize('<a href="mailto:[email protected]">[email protected]</a>'))
.toMatchInlineSnapshot(`
<body>
<a
href="mailto:[email protected]"
rel="noopener noreferrer"
target="_blank"
>
[email protected]
</a>
</body>
`);
});

it("replaces anchor tags with their text", () => {
const sanitize = createSanitize(window as any);
const el = sanitize(
Expand All @@ -98,15 +114,49 @@ it("replaces anchor tags with their text", () => {
</div>
`
);
expect(el.innerHTML).toMatchInlineSnapshot(
`
expect(el.innerHTML).toMatchInlineSnapshot(`
"
<div>
This is a link. This is another link with no href in a comment.
</div>
"
`);
});

it("does not replace anchor tags with their text if href does match inner html", () => {
const sanitize = createSanitize(window as any);
const el = sanitize(
`
<div>
This is a link where href matches <a href="http://test.com">http://test.com</a>.
</div>
`
);
expect(el.innerHTML).toMatchInlineSnapshot(`
"
<div>
This is a link where href matches <a href=\\"http://test.com\\" target=\\"_blank\\" rel=\\"noopener noreferrer\\">http://test.com</a>.
</div>
"
`);
});

it("does not replace anchor tags with their text if href does match inner html and only one has a trailing slash", () => {
const sanitize = createSanitize(window as any);
const el = sanitize(
`
<div>
This is a link where href matches <a href="http://test.com/">http://test.com</a>.
</div>
`
);
expect(el.innerHTML).toMatchInlineSnapshot(`
"
<div>
This is a link where href matches <a href=\\"http://test.com/\\" target=\\"_blank\\" rel=\\"noopener noreferrer\\">http://test.com</a>.
</div>
"
`);
});

it("allows bolded tags", () => {
Expand Down
37 changes: 33 additions & 4 deletions src/core/common/helpers/sanitize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,44 @@ export function convertGQLRTEConfigToRTEFeatures(
};
}

const MAILTO_PROTOCOL = "mailto:";

/**
* Ensure that each anchor tag is replaced with text that
* corresponds to its inner html.
* corresponds to its inner html. If the tag's href matches
* its inner html, it remains as is.
*/
const sanitizeAnchor = (node: Element) => {
if (node.nodeName === "A") {
// Turn anchor into text corresponding to innerHTML.
node.insertAdjacentText("beforebegin", node.innerHTML);
node.parentNode!.removeChild(node);
let href = node.getAttribute("href");
let innerHtml = node.innerHTML;

let mailToWithMatchingInnerHtml = false;
if (href) {
const url = new URL(href);

// Check for a mailto: link with corresponding inner html
if (url.protocol === MAILTO_PROTOCOL) {
if (href.replace(url.protocol, "") === innerHtml) {
mailToWithMatchingInnerHtml = true;
}
}

// Account for whether trailing slashes are included or not
href = href?.endsWith("/") ? href : (href += "/");
innerHtml = innerHtml.endsWith("/") ? innerHtml : (innerHtml += "/");
}

// When the anchor tag's inner html matches its href
if ((href && href === innerHtml) || mailToWithMatchingInnerHtml) {
// Ensure we wrap all the links with the target + rel set
node.setAttribute("target", "_blank");
node.setAttribute("rel", "noopener noreferrer");
} else {
// Otherwise, turn the anchor link into text corresponding to its inner html
node.insertAdjacentText("beforebegin", node.innerHTML);
node.parentNode!.removeChild(node);
}
}
};

Expand Down
3 changes: 3 additions & 0 deletions src/core/server/app/router/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ const clientHandler = ({
req.coral.tenant?.featureFlags?.filter(validFeatureFlagsFilter(req.user)) ||
[];

const flattenReplies = req.coral.tenant?.flattenReplies || false;

res.render(viewTemplate, {
analytics,
staticURI: config.staticURI,
Expand All @@ -156,6 +158,7 @@ const clientHandler = ({
...config,
featureFlags,
tenantDomain: req.coral.tenant?.domain,
flattenReplies,
},
customCSSURL: enableCustomCSSQuery ? req.query.customCSSURL : null,
});
Expand Down
1 change: 1 addition & 0 deletions src/core/server/app/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export function createRouter(app: AppOptions, options: RouterOptions) {
staticURI: app.config.get("static_uri") || "/",
graphQLSubscriptionURI: app.config.get("graphql_subscription_uri") || "",
featureFlags: [],
flattenReplies: false,
forceAdminLocalAuth: app.config.get("force_admin_local_auth"),
};

Expand Down

0 comments on commit 034865e

Please sign in to comment.