From 20eb4bc29600975ea9b6d74426204b8f6871bc27 Mon Sep 17 00:00:00 2001 From: ikasoba <57828948+ikasoba@users.noreply.github.com> Date: Sat, 27 Apr 2024 20:26:55 +0900 Subject: [PATCH] =?UTF-8?q?Fix(backend):=20ActivityPub=E3=81=A7=E3=81=AEHT?= =?UTF-8?q?ML=E3=81=B8=E3=81=AE=E3=82=B7=E3=83=AA=E3=82=A2=E3=83=A9?= =?UTF-8?q?=E3=82=A4=E3=82=BA=E3=82=92=E4=BF=AE=E6=AD=A3=20(#13752)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * devモードでもActivityPub系エンドポイントへアクセスできるように * ActivityPubでのHTMLのシリアライズを修正 * ハードコードしていたurlを`httpUrl`へ修正 * テストの追加 --- packages/backend/src/core/MfmService.ts | 8 +++++--- packages/backend/test/unit/MfmService.ts | 6 ++++++ packages/frontend/vite.config.local-dev.ts | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/packages/backend/src/core/MfmService.ts b/packages/backend/src/core/MfmService.ts index 2fb731201b..9786f8b8bb 100644 --- a/packages/backend/src/core/MfmService.ts +++ b/packages/backend/src/core/MfmService.ts @@ -6,7 +6,7 @@ import { URL } from 'node:url'; import { Inject, Injectable } from '@nestjs/common'; import * as parse5 from 'parse5'; -import { Window } from 'happy-dom'; +import { Window, XMLSerializer } from 'happy-dom'; import { DI } from '@/di-symbols.js'; import type { Config } from '@/config.js'; import { intersperse } from '@/misc/prelude/array.js'; @@ -247,6 +247,8 @@ export class MfmService { const doc = window.document; + const body = doc.createElement('p'); + function appendChildren(children: mfm.MfmNode[], targetElement: any): void { if (children) { for (const child of children.map(x => (handlers as any)[x.type](x))) targetElement.appendChild(child); @@ -457,8 +459,8 @@ export class MfmService { }, }; - appendChildren(nodes, doc.body); + appendChildren(nodes, body); - return `

${doc.body.innerHTML}

`; + return new XMLSerializer().serializeToString(body); } } diff --git a/packages/backend/test/unit/MfmService.ts b/packages/backend/test/unit/MfmService.ts index f613fe9c7c..fd4a03413b 100644 --- a/packages/backend/test/unit/MfmService.ts +++ b/packages/backend/test/unit/MfmService.ts @@ -39,6 +39,12 @@ describe('MfmService', () => { const output = '

foo bar

'; assert.equal(mfmService.toHtml(mfm.parse(input)), output); }); + + test('escape', () => { + const input = '```\n

Hello, world!

\n```'; + const output = '

<p>Hello, world!</p>

'; + assert.equal(mfmService.toHtml(mfm.parse(input)), output); + }); }); describe('fromHtml', () => { diff --git a/packages/frontend/vite.config.local-dev.ts b/packages/frontend/vite.config.local-dev.ts index 460787fd05..f9dff13b15 100644 --- a/packages/frontend/vite.config.local-dev.ts +++ b/packages/frontend/vite.config.local-dev.ts @@ -51,6 +51,22 @@ const devConfig = { '/_info_card_': httpUrl, '/bios': httpUrl, '/cli': httpUrl, + '/inbox': httpUrl, + '/notes': { + target: httpUrl, + headers: { + 'Accept': 'application/activity+json', + }, + }, + '/users': { + target: httpUrl, + headers: { + 'Accept': 'application/activity+json', + }, + }, + '/.well-known': { + target: httpUrl, + }, }, }, build: {