fix(memo): sanitize the tag used in memo export file names

This commit is contained in:
Yun Chan 2026-09-28 00:53:45 +09:00
parent 5fef311575
commit 95aa95e986
3 changed files with 112 additions and 3 deletions

View file

@ -11,6 +11,7 @@ import type { MemoTagRow } from '../db/schema'
import { getLogger } from './LoggerService'
import { getCloudSyncService } from './CloudSyncService'
import { memoTagKey, normalizeMemoTag } from './sync/memo-tag-sync'
import { buildMemoExportFileName } from './memo/memo-export-file-name'
import { D3ROError, ErrorCode } from '@d3ro/core/errors'
import type {
MemoTag,
@ -285,9 +286,14 @@ class MemoService {
fs.mkdirSync(exportDir, { recursive: true })
}
const timestamp = Date.now()
const tagSuffix = params.tag ? `_${params.tag}` : ''
const filePath = path.join(exportDir, `memo${tagSuffix}_${timestamp}.md`)
const fileName = buildMemoExportFileName(
params.tag ? normalizeMemoTag(params.tag) : undefined,
Date.now()
)
const filePath = path.join(exportDir, fileName)
if (path.dirname(path.resolve(filePath)) !== path.resolve(exportDir)) {
throw new D3ROError(ErrorCode.MemoExportFailed, 'Memo export path escapes the exports folder')
}
try {
fs.writeFileSync(filePath, lines.join('\n'), 'utf-8')