From 21fdfbf2076e8ec4a990110820211154546dc829 Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Thu, 4 Sep 2025 22:30:06 +0200 Subject: [PATCH] Normalizes output folder path for settings Ensures that the output folder path is normalized before being saved in the settings. This prevents issues with inconsistent or invalid paths. --- main.ts | 10 ++++++---- src/ui/modal/sections/GeneralSection.ts | 7 ++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/main.ts b/main.ts index 70906da..ae01619 100644 --- a/main.ts +++ b/main.ts @@ -16,7 +16,8 @@ import { Menu, MarkdownView, Editor, - AbstractInputSuggest + AbstractInputSuggest, + normalizePath } from 'obsidian'; import { obsidianTypstPDFExportSettings, DEFAULT_SETTINGS, ExportFormat } from './src/core/settings'; @@ -1265,11 +1266,12 @@ class ObsidianTypstPDFExportSettingTab extends PluginSettingTab { .setPlaceholder('exports') .setValue(this.plugin.settings.outputFolder) .onChange(async (value) => { - if (!SecurityUtils.validateOutputPath(value)) { - new Notice(`Invalid output folder: ${SecurityUtils.getPathValidationError(value)}`); + const normalizedValue = normalizePath(value); + if (!SecurityUtils.validateOutputPath(normalizedValue)) { + new Notice(`Invalid output folder: ${SecurityUtils.getPathValidationError(normalizedValue)}`); return; } - this.plugin.settings.outputFolder = value; + this.plugin.settings.outputFolder = normalizedValue; await this.plugin.saveSettings(); }); diff --git a/src/ui/modal/sections/GeneralSection.ts b/src/ui/modal/sections/GeneralSection.ts index ab73072..3a0c63e 100644 --- a/src/ui/modal/sections/GeneralSection.ts +++ b/src/ui/modal/sections/GeneralSection.ts @@ -3,7 +3,7 @@ * Handles template selection, format options, and output settings */ -import { Setting, App } from 'obsidian'; +import { Setting, App, normalizePath } from 'obsidian'; import { ModalSection, ModalState, ValidationResult } from '../modalTypes'; import { ExportFormat } from '../../../core/settings'; import { FolderSuggest } from '../../components/FolderSuggest'; @@ -78,7 +78,8 @@ export class GeneralSection implements ModalSection { .setPlaceholder('exports') .setValue(state.settings.outputFolder || 'exports') .onChange(value => { - state.updateSettings({ outputFolder: value }); + const normalizedValue = normalizePath(value); + state.updateSettings({ outputFolder: normalizedValue }); }); this.outputFolderInput = input.inputEl; @@ -101,7 +102,7 @@ export class GeneralSection implements ModalSection { // Validate output folder if (this.outputFolderInput) { - const value = this.outputFolderInput.value.trim(); + const value = normalizePath(this.outputFolderInput.value.trim()); if (!SecurityUtils.validateOutputPath(value)) { errors.push(SecurityUtils.getPathValidationError(value)); }