Skip to content

[Bug] Critical Networking & Persistence Failures: Duplicate Row Logic, Regex Crashes, and History Data Loss #1642

@dhairyajangir

Description

@dhairyajangir

Describe the bug/problem

Three high-severity regressions have been identified in the networking and persistence layers:

  • Networking: getEnabledRows uses indexOf to check if a row is enabled. Since indexOf returns the first occurrence of a value, duplicate parameter names (e.g., two headers named Set-Cookie) result in the second parameter always mirroring the enabled/disabled state of the first.
Image
  • Utils: substituteVariables constructs a global RegExp using environment variable keys without escaping them. Keys containing metacharacters (e.g., user.id or base+url) cause a FormatException, crashing the request sequence.
Image
  • Persistence: addHistoryRequest and editHistoryRequest trigger Hive writes without the await keyword. This creates a race condition where the app can be closed before the history index is updated, leading to orphaned records and data loss.
Image

Steps to Reproduce the bug/problem

  1. For Row Logic: Create two query parameters: key=1 (Enabled) and key=2 (Disabled). Send the request; note that key=2 is incorrectly included.
  2. For Regex Crash: Define an environment variable with a dot, such as api.key. Use {{api.key}} in any request field and attempt to send.
  3. For Data Loss: Send a request and force-close the app immediately. Upon restart, the request will not appear in the history list.

Expected behavior

  • Rows: Parameters should be filtered by their specific list index, not by value-based search.
  • Regex: Variable keys should be escaped using RegExp.escape() to support common naming conventions like dots and dashes.
  • Persistence: All database writes must be fully awaited to ensure atomic-like updates to history metadata and request bodies.

Technical Details & Fix Direction

  • File: packages/better_networking/lib/utils/http_request_utils.dart
    • Fix: Replace .where with an index-based for loop or .asMap().entries.where.
  • File: lib/utils/envvar_utils.dart
    • Fix: Map keys through an escape function before joining into the regex string.
  • File: lib/providers/history_providers.dart
    • Fix: Add await to setHistoryIds() and setHistoryMeta() calls.

Device Info (The device where you encountered this issue)

  • OS: Windows
  • Version: Windows 11 22H2
  • Environment: Production & Development environments

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    In progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions