Skip to content

fix: escape regex keys in substituteVariables and await Hive writes in history providers#1652

Open
nazifsco wants to merge 1 commit into
foss42:mainfrom
nazifsco:fix/envvar-regex-and-history-await
Open

fix: escape regex keys in substituteVariables and await Hive writes in history providers#1652
nazifsco wants to merge 1 commit into
foss42:mainfrom
nazifsco:fix/envvar-regex-and-history-await

Conversation

@nazifsco
Copy link
Copy Markdown

Fixes two of the three issues reported in #1642.

Fix 1 -- envvar_utils.dart

substituteVariables built a regex from env var keys without escaping them. Keys containing regex metacharacters like api.key (dot) or base+url (plus) caused a FormatException crash before the request was sent.

// Before
final regex = RegExp("{{(${envVarMap.keys.join('|')})}}");

// After
final escapedKeys = envVarMap.keys.map(RegExp.escape).join('|');
final regex = RegExp("{{($escapedKeys)}}");

Fix 2 -- history_providers.dart

addHistoryRequest and editHistoryRequest called setHistoryIds() and setHistoryMeta() without await. This created a race condition where the app could be closed before the history index was persisted, leaving orphaned records and causing data loss on restart. Also changed both method return types from void to Future<void>.

// Before
hiveHandler.setHistoryIds(updatedHistoryKeys);
hiveHandler.setHistoryMeta(id, model.metaData.toJson());

// After
await hiveHandler.setHistoryIds(updatedHistoryKeys);
await hiveHandler.setHistoryMeta(id, model.metaData.toJson());

Note: the third issue in #1642 (getEnabledRows duplicate row bug) was already fixed in #1465.

…n history providers

- envvar_utils.dart: wrap env var keys with RegExp.escape() before
  building the substitution regex. Keys containing metacharacters like
  dots (api.key) or plus signs (base+url) previously caused a
  FormatException crash. Fixes foss42#1642.

- history_providers.dart: add await to setHistoryIds() and
  setHistoryMeta() calls in addHistoryRequest and editHistoryRequest.
  Without await, a race condition allowed the app to close before the
  history index was written, causing orphaned records and data loss.
  Also changed return types from void to Future<void> so callers can
  await completion. Fixes foss42#1642.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

1 participant