Skip to content

Commit 672b454

Browse files
committed
fix codeql scanners
1 parent 468eb3e commit 672b454

4 files changed

Lines changed: 44 additions & 18 deletions

File tree

bun.lock

Lines changed: 28 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/airtable.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ function computeClosedAt(poll) {
3434
}
3535

3636
async function upsertByKey(table, keyField, keyValue, fields, createOnlyFields = {}) {
37-
const escaped = String(keyValue).replace(/'/g, "\\'");
37+
const formulaValue = JSON.stringify(String(keyValue));
3838
const existing = await base(table)
39-
.select({ maxRecords: 1, filterByFormula: `{${keyField}} = '${escaped}'` })
39+
.select({ maxRecords: 1, filterByFormula: `{${keyField}} = ${formulaValue}` })
4040
.firstPage();
4141

4242
if (existing.length) {

lib/commands/define.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1+
import { compile } from "html-to-text";
2+
13
import { escapeMrkdwn } from "../postingGate.js";
24

35
const MSG_NOT_FOUND = (term) => `:red-x: No definition found for "${escapeMrkdwn(term)}".`;
46
const moreSensesLine = (n, term) =>
57
`<https://en.wiktionary.org/wiki/${encodeURIComponent(term)}|+${n} more sense${n === 1 ? "" : "s"} not shown>`;
68

9+
const wikiHtmlToText = compile({
10+
wordwrap: false,
11+
selectors: [
12+
{ selector: "a", format: "inline" },
13+
{ selector: "ol", format: "skip" },
14+
{ selector: "script", format: "skip" },
15+
{ selector: "style", format: "skip" },
16+
],
17+
});
18+
719
function stripWikiHtml(html) {
8-
return (html || "")
9-
.replace(/<style[^>]*>[\s\S]*?<\/style>/gi, "")
10-
.replace(/<ol[\s>][\s\S]*$/i, "")
11-
.replace(/<[^>]+>/g, "")
12-
.replace(/&amp;/g, "&")
13-
.replace(/&lt;/g, "<")
14-
.replace(/&gt;/g, ">")
15-
.replace(/&#39;/g, "'")
16-
.replace(/&quot;/g, '"')
17-
.trim();
20+
return wikiHtmlToText(html || "").trim();
1821
}
1922

2023
function englishFirst(sections) {
@@ -72,11 +75,6 @@ export default {
7275
});
7376
if (rest.length)
7477
return respond({ response_type: "ephemeral", text: ":red-x: One word at a time, please." });
75-
if (term.length > 50)
76-
return respond({
77-
response_type: "ephemeral",
78-
text: ":red-x: One word at a time, please.",
79-
});
8078
if (term.length > 50)
8179
return respond({
8280
response_type: "ephemeral",

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"dotenv": "^17.4.2",
2626
"drizzle-orm": "0.45.2",
2727
"hono": "^4.13.3",
28+
"html-to-text": "^10.0.1",
2829
"tldts": "^7.4.10"
2930
},
3031
"devDependencies": {

0 commit comments

Comments
 (0)