From 727f3a3eb4369fc51b0589e40d6433dc8367a29b Mon Sep 17 00:00:00 2001 From: Yohane Date: Thu, 27 Feb 2025 17:02:49 +0800 Subject: [PATCH] Fix:Regex expression parsing usb incorrectly (#94) --- adb_client/src/server/models/device_long.rs | 2 +- tests/tests.rs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/adb_client/src/server/models/device_long.rs b/adb_client/src/server/models/device_long.rs index 5daf9d0..6ce70a4 100644 --- a/adb_client/src/server/models/device_long.rs +++ b/adb_client/src/server/models/device_long.rs @@ -6,7 +6,7 @@ use crate::{DeviceState, RustADBError}; use regex::bytes::Regex; static DEVICES_LONG_REGEX: LazyLock = LazyLock::new(|| { - Regex::new("^(?P\\S+)\\s+(?P\\w+) ((usb:(?P.*)|(?P\\d-\\d)) )?(product:(?P\\w+) model:(?P\\w+) device:(?P\\w+) )?transport_id:(?P\\d+)$").expect("cannot build devices long regex") + Regex::new(r"^(?P\S+)\s+(?P\w+)\s+(usb:(?P\S+)|(?P\S+))?\s*(product:(?P\w+)\s+model:(?P\w+)\s+device:(?P\w+)\s+)?transport_id:(?P\d+)$").expect("cannot build devices long regex") }); /// Represents a new device with more informations. diff --git a/tests/tests.rs b/tests/tests.rs index 9e22768..53d541f 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -42,7 +42,10 @@ mod tests { #[test] fn test_static_devices_long() { - let inputs = ["7a5158f05122195aa device 1-5 product:gts210vewifixx model:SM_T813 device:gts210vewifi transport_id:4"]; + let inputs = ["7a5158f05122195aa device 1-5 product:gts210vewifixx model:SM_T813 device:gts210vewifi transport_id:4", + "n311r05e device usb:0-1.5 product:alioth model:M2012K11AC device:alioth transport_id:58", + "192.168.100.192:5555 device product:alioth model:M2012K11AC device:alioth transport_id:97", + "emulator-5554 device product:sdk_gphone64_arm64 model:sdk_gphone64_arm64 device:emu64a transport_id:101"]; for input in inputs { DeviceLong::try_from(input.as_bytes().to_vec()) .expect(&format!("cannot parse input: '{input}'"));