Skip to content

Commit 3791f19

Browse files
committed
feat(source-control): decode Tangled PR title entities
1 parent 7ea8c2f commit 3791f19

4 files changed

Lines changed: 16 additions & 3 deletions

File tree

‎packages/source-control-tangled/package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
"@t3tools/provider-core": "workspace:*",
3838
"@t3tools/shared": "workspace:*",
3939
"@t3tools/source-control-core": "workspace:*",
40-
"effect": "catalog:"
40+
"effect": "catalog:",
41+
"entities": "4.5.0"
4142
},
4243
"devDependencies": {
4344
"@effect/vitest": "catalog:",

‎packages/source-control-tangled/src/server/tangledPulls.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,15 @@ describe("offsetFromRows", () => {
146146
});
147147

148148
describe("parsePullPageRows", () => {
149+
it("decodes title character references so numbered reads match the CLI title", () => {
150+
const title = "Fix <tag> & \"parsing\" 'quotes' 🚀 &lt;";
151+
const html =
152+
'<a href="/alice.example/repo/pulls/1">Fix &lt;tag&gt; &amp; &#34;parsing&#34; &#x27;quotes&#x27; &#x1F680; &amp;lt; <span>#1</span></a>';
153+
const rows = parsePullPageRows(html, "alice.example/repo");
154+
assert.deepStrictEqual(rows, [{ number: 1, title }]);
155+
assert.strictEqual(offsetFromRows(rows, numberPulls([pull("a", title)])), 0);
156+
});
157+
149158
it("reads the number and title a tangled.org page prints", () => {
150159
const html = `
151160
<a href="/tangled.org/knot-docker/pulls/19" class="dark:text-white">

‎packages/source-control-tangled/src/server/tangledPulls.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* @module source-control-tangled/server/tangledPulls
66
*/
77
import * as Schema from "effect/Schema";
8+
import { decodeHTML } from "entities";
89

910
/**
1011
* One entry of `tg pr list`. Without a `--state` filter `tg` answers with every state, so the
@@ -97,8 +98,7 @@ export function parsePullPageRows(
9798
const rows: Array<{ number: number; title: string }> = [];
9899
for (const match of html.matchAll(pattern)) {
99100
const number = Number(match[1]);
100-
const title = (match[2] ?? "")
101-
.replace(/<[^>]+>/gu, "")
101+
const title = decodeHTML((match[2] ?? "").replace(/<[^>]+>/gu, ""))
102102
.replace(/\s+/gu, " ")
103103
.trim()
104104
.replace(/\s*#\d+$/u, "");

‎pnpm-lock.yaml‎

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)