mirror of
https://github.com/matrix-org/mjolnir.git
synced 2024-10-01 05:36:06 +00:00
reimplement htmlEscape
This commit is contained in:
parent
0b7da86b9c
commit
c2661105db
@ -32,7 +32,6 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"config": "^3.3.6",
|
||||
"escape-html": "^1.0.3",
|
||||
"express": "^4.17",
|
||||
"html-to-text": "^8.0.0",
|
||||
"js-yaml": "^4.1.0",
|
||||
|
@ -16,8 +16,7 @@ limitations under the License.
|
||||
|
||||
import { LogLevel, LogService, TextualMessageEventContent } from "matrix-bot-sdk";
|
||||
import config from "./config";
|
||||
import { replaceRoomIdsWithPills } from "./utils";
|
||||
import * as htmlEscape from "escape-html";
|
||||
import { htmlEscape, replaceRoomIdsWithPills } from "./utils";
|
||||
|
||||
const levelToFn = {
|
||||
[LogLevel.DEBUG.toString()]: LogService.debug,
|
||||
|
@ -40,7 +40,7 @@ import { ProtectionSettingValidationError } from "./protections/ProtectionSettin
|
||||
import { UnlistedUserRedactionQueue } from "./queues/UnlistedUserRedactionQueue";
|
||||
import { Healthz } from "./health/healthz";
|
||||
import { EventRedactionQueue, RedactUserInRoom } from "./queues/EventRedactionQueue";
|
||||
import * as htmlEscape from "escape-html";
|
||||
import { htmlEscape } from "./utils";
|
||||
import { ReportManager } from "./report/ReportManager";
|
||||
import { WebAPIs } from "./webapis/WebAPIs";
|
||||
import RuleServer from "./models/RuleServer";
|
||||
@ -851,7 +851,7 @@ export class Mjolnir {
|
||||
} else if (ruleKind === RULE_ROOM) {
|
||||
ruleKind = 'room';
|
||||
}
|
||||
html += `<li>${change.changeType} ${htmlEscape(ruleKind)} (<code>${htmlEscape(rule.recommendation)}</code>): <code>${htmlEscape(rule.entity)}</code> (${htmlEscape(rule.reason)})</li>`;
|
||||
html += `<li>${change.changeType} ${htmlEscape(ruleKind)} (<code>${htmlEscape(rule.recommendation ?? "")}</code>): <code>${htmlEscape(rule.entity)}</code> (${htmlEscape(rule.reason)})</li>`;
|
||||
text += `* ${change.changeType} ${ruleKind} (${rule.recommendation}): ${rule.entity} (${rule.reason})\n`;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ limitations under the License.
|
||||
|
||||
import { Mjolnir } from "../Mjolnir";
|
||||
import { RichReply } from "matrix-bot-sdk";
|
||||
import * as htmlEscape from "escape-html";
|
||||
import { htmlEscape } from "../utils";
|
||||
|
||||
// !mjolnir move <alias> <new room ID>
|
||||
export async function execMoveAliasCommand(roomId: string, event: any, mjolnir: Mjolnir, parts: string[]) {
|
||||
|
@ -19,7 +19,7 @@ import { execStatusCommand } from "./StatusCommand";
|
||||
import { execBanCommand, execUnbanCommand } from "./UnbanBanCommand";
|
||||
import { execDumpRulesCommand } from "./DumpRulesCommand";
|
||||
import { extractRequestError, LogService, RichReply } from "matrix-bot-sdk";
|
||||
import * as htmlEscape from "escape-html";
|
||||
import { htmlEscape } from "../utils";
|
||||
import { execSyncCommand } from "./SyncCommand";
|
||||
import { execPermissionCheckCommand } from "./PermissionCheckCommand";
|
||||
import { execCreateListCommand } from "./CreateBanListCommand";
|
||||
|
@ -16,7 +16,7 @@ limitations under the License.
|
||||
|
||||
import { Mjolnir } from "../Mjolnir";
|
||||
import { RichReply } from "matrix-bot-sdk";
|
||||
import * as htmlEscape from "escape-html";
|
||||
import { htmlEscape } from "../utils";
|
||||
|
||||
// !mjolnir rules
|
||||
export async function execDumpRulesCommand(roomId: string, event: any, mjolnir: Mjolnir) {
|
||||
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import * as htmlEscape from "escape-html";
|
||||
import { htmlEscape } from "../utils";
|
||||
import { Mjolnir } from "../Mjolnir";
|
||||
import { extractRequestError, LogService, RichReply } from "matrix-bot-sdk";
|
||||
import { PROTECTIONS } from "../protections/protections";
|
||||
|
@ -17,7 +17,7 @@ limitations under the License.
|
||||
import { PowerLevelAction } from "matrix-bot-sdk/lib/models/PowerLevelAction";
|
||||
import { LogService, UserID } from "matrix-bot-sdk";
|
||||
import { htmlToText } from "html-to-text";
|
||||
import * as htmlEscape from "escape-html";
|
||||
import { htmlEscape } from "../utils";
|
||||
import { JSDOM } from 'jsdom';
|
||||
|
||||
import { Mjolnir } from "../Mjolnir";
|
||||
|
10
src/utils.ts
10
src/utils.ts
@ -29,9 +29,17 @@ import {
|
||||
} from "matrix-bot-sdk";
|
||||
import { logMessage } from "./LogProxy";
|
||||
import config from "./config";
|
||||
import * as htmlEscape from "escape-html";
|
||||
import { ClientRequest, IncomingMessage } from "http";
|
||||
|
||||
export function htmlEscape(input: string): string {
|
||||
return input.replace(/["&<>]/g, (char: string) => ({
|
||||
['"'.charCodeAt(0)]: """,
|
||||
["&".charCodeAt(0)]: "&",
|
||||
["<".charCodeAt(0)]: "<",
|
||||
[">".charCodeAt(0)]: ">"
|
||||
})[char.charCodeAt(0)]);
|
||||
}
|
||||
|
||||
export function setToArray<T>(set: Set<T>): T[] {
|
||||
const arr: T[] = [];
|
||||
for (const v of set) {
|
||||
|
Loading…
Reference in New Issue
Block a user