mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Prevent producing "undefined" strings (#10042)
Fixes a bug in search-menu-results (type: "group"), where: ```javascript const fullName = escapeExpression(group.fullName); const name = escapeExpression(group.name); const groupNames = [h("span.name", fullName || name)]; ``` `groupNames` could end up having value "undefined" if a group doesn't have a `fullName`.
This commit is contained in:
parent
d66ccabdb1
commit
a859d507e7
@ -25,6 +25,10 @@ export function translateSize(size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function escapeExpression(string) {
|
export function escapeExpression(string) {
|
||||||
|
if (!string) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
// don't escape SafeStrings, since they're already safe
|
// don't escape SafeStrings, since they're already safe
|
||||||
if (string instanceof Handlebars.SafeString) {
|
if (string instanceof Handlebars.SafeString) {
|
||||||
return string.toString();
|
return string.toString();
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
/* global Int8Array:true */
|
/* global Int8Array:true */
|
||||||
import {
|
import {
|
||||||
|
escapeExpression,
|
||||||
emailValid,
|
emailValid,
|
||||||
extractDomainFromUrl,
|
extractDomainFromUrl,
|
||||||
avatarUrl,
|
avatarUrl,
|
||||||
@ -14,9 +15,30 @@ import {
|
|||||||
fillMissingDates,
|
fillMissingDates,
|
||||||
inCodeBlock
|
inCodeBlock
|
||||||
} from "discourse/lib/utilities";
|
} from "discourse/lib/utilities";
|
||||||
|
import Handlebars from "handlebars";
|
||||||
|
|
||||||
QUnit.module("lib:utilities");
|
QUnit.module("lib:utilities");
|
||||||
|
|
||||||
|
QUnit.test("escapeExpression", assert => {
|
||||||
|
assert.equal(
|
||||||
|
escapeExpression(">"),
|
||||||
|
">",
|
||||||
|
"escapes unsafe characters"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
escapeExpression(new Handlebars.SafeString(">")),
|
||||||
|
">",
|
||||||
|
"does not double-escape safe strings"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
escapeExpression(undefined),
|
||||||
|
"",
|
||||||
|
"returns a falsy string when given a falsy value"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
QUnit.test("emailValid", assert => {
|
QUnit.test("emailValid", assert => {
|
||||||
assert.ok(
|
assert.ok(
|
||||||
emailValid("Bob@example.com"),
|
emailValid("Bob@example.com"),
|
||||||
|
Loading…
Reference in New Issue
Block a user