Skip to content

Stop metadata load from panicking on a bad pattern - #726

Merged
keith-hall merged 1 commit into
trishume:masterfrom
SebTardif:fix/metadata-load-panics
Dec 3, 2026
Merged

keith-hall merged 1 commit into
trishume:masterfrom
SebTardif:fix/metadata-load-panics

Conversation

@SebTardif

Copy link
Copy Markdown
Contributor

An indent pattern the regex engine rejects, and a comment marker that is not a string, both panic while loading .tmPreferences metadata.

Regex compiles on first use. increaseIndentPattern set to ( loaded, then ScopedMetadata::increase_indent panicked. TM_COMMENT_START set to a number panicked in MetadataSet::from_raw on as_str().unwrap(). Syntax patterns are already checked with Regex::try_compile at load. These metadata fields were not.

from_raw now returns an error when any indent pattern does not compile. The loader already prints that error and skips the set. A shell variable that is not a string is dropped, so a later string marker still becomes the line comment, and the rest of the set still loads.

Only src/parsing/metadata.rs changes. Regex::regex in regex.rs is unchanged. That expect is the syntax path, which already compiles at load.

Tests, command cargo test --features metadata --lib parsing::metadata::tests:

  • metadata_load_rejects_invalid_indent_pattern failed before the change because from_raw returned the pattern (. It now returns an error that names that pattern.
  • metadata_load_skips_non_string_comment_marker panicked on as_str().unwrap() before the change. It now loads # from TM_COMMENT_START_2.
  • metadata_load_skips_non_string_block_comment_marker panicked the same way on a boolean TM_COMMENT_END. It now loads with no comment marker.
  • The existing metadata tests, including the files under testdata/Packages, still pass. The ScopedMetadata doctest still passes. cargo clippy --all-features --lib -- --deny clippy::panic passes.

No docs file changes. No open issue tracks these two panics. Ref #183 is the metadata discussion, and this pull does not finish that discussion.

Introduced with metadata loading in 33cb5a6 and shell variables in fcf5e03.

Indent patterns were compiled on first use, so "(" loaded and then
panicked in increase_indent. A number or bool in TM_COMMENT_START
panicked in from_raw on as_str().unwrap().

A pattern that does not compile now fails from_raw, and the loader
skips that set. A non-string shell variable is dropped, so a later
string marker still loads.
@keith-hall
keith-hall merged commit 0a60557 into trishume:master Dec 3, 2026
5 checks passed
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.

2 participants