Skip to content

fix: Escape special regex chars in buffer lookup #1022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

seflue
Copy link
Contributor

@seflue seflue commented Aug 9, 2025

Buffer lookup failed for filenames containing [], (), . and other regex metacharacters.

  • Add utils.get_buffer_by_filename() with proper Vim regex escaping
  • Replace duplicate buffer lookup patterns across files

Summary

This PR fixes buffer lookup failures when filenames contain regex special characters like [], (), ., etc. The issue occurred because vim.fn.bufnr() patterns weren't properly escaped for Vim regex syntax, causing buffer operations (todo state, links, refiling) to fail.

Related Issues

Closes #1021

Changes

  • Add utils.get_buffer_by_filename() utility function with proper Vim regex escaping using vim.fn.escape()
  • Replace 6 duplicate buffer lookup patterns across 4 files (files/file.lua, api/init.lua, api/headline.lua,
    api/file.lua)
  • Add comprehensive test coverage for special character scenarios in tests/plenary/utils_spec.lua

Checklist

I confirm that I have:

  • Followed the
    Conventional Commits
    specification
    (e.g., feat: add new feature, fix: correct bug,
    docs: update documentation).
  • My PR title also follows the conventional commits specification.
  • Updated relevant documentation, if necessary.
  • Thoroughly tested my changes.
  • Added tests (if applicable) and verified existing tests pass with
    make test.
  • Checked for breaking changes and documented them, if any.

Buffer lookup failed for filenames containing [], (), . and other regex
metacharacters.

- Add utils.get_buffer_by_filename() with proper Vim regex escaping
- Replace duplicate buffer lookup patterns across files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Buffer lookup fails for filenames with special regex characters
1 participant