Skip to content

Commit

Permalink
fix: crash when empty share key
Browse files Browse the repository at this point in the history
Obsidian doesn't treat an empty property as a "non existant" property. So, undefined & null are different:
- null → The key exists, but the value is empty (null)
- undefined → The key doesn't exist

An empty value → create a crash

fix [Plugin][Bug]: Bug when share is empty #226
  • Loading branch information
Mara-Li authored Sep 29, 2023
1 parent 04f0ac0 commit 22c81ba
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/utils/data_validation_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function isInternalShared(
if (!frontmatter) return true;
if (isExcludedPath(properties.settings, file)) return false;
const shareKey = properties.repository?.shareKey || properties.settings.plugin.shareKey;
if (frontmatter[shareKey] === undefined) return true;
if (!frontmatter[shareKey] || frontmatter[shareKey] == null) return true;
return ["true", "1", "yes"].includes(frontmatter[shareKey].toString().toLowerCase());
}

Expand Down Expand Up @@ -75,10 +75,10 @@ export function isShared(
const otherRepoWithShareAll = settings.github.otherRepo.filter((repo) => repo.shareAll?.enable);
if (!settings.plugin.shareAll?.enable && otherRepoWithShareAll.length === 0) {
const shareKey = otherRepo ? otherRepo.shareKey : settings.plugin.shareKey;
if ( meta == null || meta[shareKey] === undefined || isExcludedPath(settings, file)) {
if ( meta == null || !meta[shareKey] || meta[shareKey] == null || isExcludedPath(settings, file)) {
return false;
}
const shareKeyInFrontmatter = meta[shareKey].toString().toLowerCase();
const shareKeyInFrontmatter:string = meta[shareKey].toString().toLowerCase();
return ["true", "1", "yes"].includes(shareKeyInFrontmatter);
} else if (settings.plugin.shareAll?.enable || otherRepoWithShareAll.length > 0) {
const allExcludedFileName = otherRepoWithShareAll.map((repo) => repo.shareAll!.excludedFileName);
Expand Down

0 comments on commit 22c81ba

Please sign in to comment.