Skip to content

Sanitize search queries and ensure config file exists; refactor menu init#1

Merged
hanfoo merged 1 commit intomainfrom
codex
Mar 15, 2026
Merged

Sanitize search queries and ensure config file exists; refactor menu init#1
hanfoo merged 1 commit intomainfrom
codex

Conversation

@hanfoo
Copy link
Owner

@hanfoo hanfoo commented Mar 15, 2026

Motivation

  • Prevent unescaped user input from breaking or injecting into search regular expressions and make configuration handling more robust when the config file is missing or corrupted.

Description

  • Add escapeRegExp and apply it in processContent and formatResults to safely escape the search query used in regexes.
  • Add ensureConfigFile to create a default config at configName, ensure parent directories exist, and recover from corrupted JSON by overwriting with defaults.
  • Refactor initMenu to use ensureConfigFile and remove the previous fragile file-read/try-catch flow while preserving upgrade logic for older config shapes.
  • Guard fs.watch(configName) on app ready with fs.existsSync(configName) so file-watching is only set when the config file exists.

Testing

  • No automated tests were added or run for this change.

Codex Task

@hanfoo hanfoo marked this pull request as ready for review March 15, 2026 15:12
@hanfoo hanfoo merged commit 1a668af into main Mar 15, 2026
@hanfoo hanfoo deleted the codex branch March 15, 2026 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant