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.
This commit is contained in:
AlexKucera committed 2025-09-04 22:30:06 +02:00
1 parent 151dc537a5
commit 21fdfbf207
2 files changed
+10 -7

No files matched your search

+6 -4
View File
@@ -16,7 +16,8 @@ import {
Menu, Menu,
MarkdownView, MarkdownView,
Editor, Editor,
AbstractInputSuggest AbstractInputSuggest,
normalizePath
} from 'obsidian'; } from 'obsidian';
import { obsidianTypstPDFExportSettings, DEFAULT_SETTINGS, ExportFormat } from './src/core/settings'; import { obsidianTypstPDFExportSettings, DEFAULT_SETTINGS, ExportFormat } from './src/core/settings';
@@ -1265,11 +1266,12 @@ class ObsidianTypstPDFExportSettingTab extends PluginSettingTab {
.setPlaceholder('exports') .setPlaceholder('exports')
.setValue(this.plugin.settings.outputFolder) .setValue(this.plugin.settings.outputFolder)
.onChange(async (value) => { .onChange(async (value) => {
if (!SecurityUtils.validateOutputPath(value)) { const normalizedValue = normalizePath(value);
new Notice(`Invalid output folder: ${SecurityUtils.getPathValidationError(value)}`); if (!SecurityUtils.validateOutputPath(normalizedValue)) {
new Notice(`Invalid output folder: ${SecurityUtils.getPathValidationError(normalizedValue)}`);
return; return;
} }
this.plugin.settings.outputFolder = value; this.plugin.settings.outputFolder = normalizedValue;
await this.plugin.saveSettings(); await this.plugin.saveSettings();
}); });
+4 -3
View File
@@ -3,7 +3,7 @@
* Handles template selection, format options, and output settings * 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 { ModalSection, ModalState, ValidationResult } from '../modalTypes';
import { ExportFormat } from '../../../core/settings'; import { ExportFormat } from '../../../core/settings';
import { FolderSuggest } from '../../components/FolderSuggest'; import { FolderSuggest } from '../../components/FolderSuggest';
@@ -78,7 +78,8 @@ export class GeneralSection implements ModalSection {
.setPlaceholder('exports') .setPlaceholder('exports')
.setValue(state.settings.outputFolder || 'exports') .setValue(state.settings.outputFolder || 'exports')
.onChange(value => { .onChange(value => {
state.updateSettings({ outputFolder: value }); const normalizedValue = normalizePath(value);
state.updateSettings({ outputFolder: normalizedValue });
}); });
this.outputFolderInput = input.inputEl; this.outputFolderInput = input.inputEl;
@@ -101,7 +102,7 @@ export class GeneralSection implements ModalSection {
// Validate output folder // Validate output folder
if (this.outputFolderInput) { if (this.outputFolderInput) {
const value = this.outputFolderInput.value.trim(); const value = normalizePath(this.outputFolderInput.value.trim());
if (!SecurityUtils.validateOutputPath(value)) { if (!SecurityUtils.validateOutputPath(value)) {
errors.push(SecurityUtils.getPathValidationError(value)); errors.push(SecurityUtils.getPathValidationError(value));
} }