Skip to content

Commit

Permalink
fix(Threading): 🐛 Disallow illegal filename characters in threadingTe…
Browse files Browse the repository at this point in the history
…mplate (fix #288)
  • Loading branch information
SkepticMystic committed Jan 28, 2022
1 parent 3efc3b8 commit b08073b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
21 changes: 19 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9649,6 +9649,17 @@ const BC_FIELDS_INFO = [
},
];
const BC_ALTS = BC_FIELDS_INFO.filter((f) => f.alt).map((f) => f.field);
const ILLEGAL_FILENAME_CHARS = [
"\\",
"/",
":",
"*",
"?",
'"',
"<",
">",
"|",
];
const DEFAULT_SETTINGS = {
addDendronNotes: false,
aliasesInIndex: false,
Expand All @@ -9667,7 +9678,7 @@ const DEFAULT_SETTINGS = {
enableRelationSuggestor: false,
fieldSuggestor: true,
filterImpliedSiblingsOfDifferentTypes: false,
jugglLayout: 'hierarchy',
jugglLayout: "hierarchy",
limitWriteBCCheckboxes: [],
CHECKBOX_STATES_OVERWRITTEN: false,
gridDots: false,
Expand Down Expand Up @@ -37214,7 +37225,13 @@ function addThreadingSettings(plugin, cmdsDetails) {
.addText((text) => {
text.setValue(settings.threadingTemplate);
text.inputEl.onblur = async () => {
settings.threadingTemplate = text.getValue();
const value = text.getValue();
if (ILLEGAL_FILENAME_CHARS.some((char) => value.includes(char))) {
new obsidian.Notice(`File name cannot contain any of these characters: ${ILLEGAL_FILENAME_CHARS.join(" ")}`);
text.setValue(settings.threadingTemplate);
return;
}
settings.threadingTemplate = value;
await plugin.saveSettings();
};
});
Expand Down
21 changes: 18 additions & 3 deletions src/Settings/ThreadingSettings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { Setting } from "obsidian";
import { ARROW_DIRECTIONS, DEFAULT_SETTINGS, DIRECTIONS } from "../constants";
import { Notice, Setting } from "obsidian";
import {
ARROW_DIRECTIONS,
DEFAULT_SETTINGS,
DIRECTIONS,
ILLEGAL_FILENAME_CHARS,
} from "../constants";
import type BCPlugin from "../main";
import { fragWithHTML, subDetails } from "./BreadcrumbsSettingTab";

Expand Down Expand Up @@ -40,7 +45,17 @@ export function addThreadingSettings(
.addText((text) => {
text.setValue(settings.threadingTemplate);
text.inputEl.onblur = async () => {
settings.threadingTemplate = text.getValue();
const value = text.getValue();
if (ILLEGAL_FILENAME_CHARS.some((char) => value.includes(char))) {
new Notice(
`File name cannot contain any of these characters: ${ILLEGAL_FILENAME_CHARS.join(
" "
)}`
);
text.setValue(settings.threadingTemplate);
return;
}
settings.threadingTemplate = value;
await plugin.saveSettings();
};
});
Expand Down
14 changes: 13 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,18 @@ export const BC_FIELDS_INFO = [

export const BC_ALTS = BC_FIELDS_INFO.filter((f) => f.alt).map((f) => f.field);

export const ILLEGAL_FILENAME_CHARS = [
"\\",
"/",
":",
"*",
"?",
'"',
"<",
">",
"|",
];

export const DEFAULT_SETTINGS: BCSettings = {
addDendronNotes: false,
aliasesInIndex: false,
Expand All @@ -255,7 +267,7 @@ export const DEFAULT_SETTINGS: BCSettings = {
enableRelationSuggestor: false,
fieldSuggestor: true,
filterImpliedSiblingsOfDifferentTypes: false,
jugglLayout: 'hierarchy',
jugglLayout: "hierarchy",
limitWriteBCCheckboxes: [],
CHECKBOX_STATES_OVERWRITTEN: false,
gridDots: false,
Expand Down

0 comments on commit b08073b

Please sign in to comment.