Skip to content

[Bug]: isNotIndexFile falsely matches files whose names *end with* the parent directory name #81

@kornysietsma

Description

@kornysietsma

Package

markdown-confluence-sync

What happened?

Files are silently skipped from sync if their filename merely ends with the parent directory name, even when they are not index files. This causes pages to be missing from Confluence with no error or warning.

Steps to reproduce

  1. Create a docs directory named notes/
  2. Inside it, create a genuine index index.md and also file named per-experiment-notes.md (any file whose name ends with notes)
  3. Run markdown-confluence-sync in tree mode
  4. per-experiment-notes.md is not synced to Confluence — only index.md is

Root cause

isNotIndexFile calls buildIndexFileRegExp with an empty string as the separator:

export function isNotIndexFile(path) {
    const dirnamePath = basename(dirname(path));
    const pattern = buildIndexFileRegExp("", dirnamePath);  // ← sep is always ""
    return !pattern.test(path);
}

export function buildIndexFileRegExp(sep, dirnamePath) {
    const pathSep = sep === "\\" ? "\\\\" : sep;  // "" stays ""
    return new RegExp(pathSep + `(index|README|${dirnamePath}).mdx?$`);
}

The sep parameter only exists to escape backslashes for Windows in unit tests — it never injects an actual path separator when called from isNotIndexFile. The resulting regex for dirnamePath = "notes" is therefore:

/(index|README|notes).mdx?$/

This matches …/notes/per-experiment-notes.md because the full path string ends with notes.md. So isNotIndexFile returns false, isValidFile returns false, and the file is silently excluded. I suspect it would also match anything ending in index or README as well.

Expected behaviour

Only files whose full filename (not a suffix of it) matches index, README, or the directory name should be treated as index files. The simplest fix is to check the basename directly rather than testing the full path, and there's no need for as complex a regex:

export function isNotIndexFile(path) {
    const name = basename(path).replace(/\.mdx?$/, "");
    const dir  = basename(dirname(path));
    return !["index", "README", "Readme", dir].includes(name);
}

Version

2.x

Relevant log output

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions