fix(memo): sanitize the tag used in memo export file names
This commit is contained in:
parent
5fef311575
commit
95aa95e986
3 changed files with 112 additions and 3 deletions
|
|
@ -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')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue