Skip to content

Devices_long() fails to parse TCP devices with spaces in metadata fields #177

@moether

Description

@moether

Description

The devices_long() method fails with "Regex parsing error: missing field" when parsing TCP-connected Android devices that have spaces in their product or model fields.

Environment

  • adb_client version: 3.1.0
  • Rust version: 1.91.0+
  • Connection type: TCP/IP (via adb connect)

Steps to Reproduce

  1. Connect an Android device via TCP/IP: adb connect 192.168.1.100:5555
  2. Verify device appears in adb devices -l:
    192.168.1.100:5555     device product:product with spaces model:ModelName device:devicecode transport_id:1
    
  3. Call server.devices_long() in Rust code:
    let mut server = ADBServer::new(std::net::SocketAddrV4::new(Ipv4Addr::LOCALHOST, 5037));
    let devices = server.devices_long()?; // Fails here

Expected Behavior

The method should successfully parse the device and return a DeviceLong struct with:

  • product: "product with spaces"
  • model: "ModelName"
  • All other fields populated correctly

Actual Behavior

The method fails with:

Error: RustADBError::RegexParsingError

Debug output shows: "Regex parsing error: missing field"

Root Cause

The regex pattern in src/server/models/device_long.rs line 10 uses \S+ (non-whitespace characters only) for the product and model fields:

product:(?P<product>\S+)\s+model:(?P<model>\w+)

When a product field contains spaces (e.g., product:product with spaces), the regex only captures up to the first space (product), causing the rest of the line to fail to match, resulting in the "missing field" error.

Proposed Solution

Change the regex to use non-greedy matching (.+?) for product and model fields:

product:(?P<product>.+?)\s+model:(?P<model>.+?)

This pattern captures everything up to the next field marker while maintaining backward compatibility with existing device formats.

This patch should fix the issue:
device_long.patch

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions