Accepting empty deviceName, when requesting a BluetoothDevice.

This commit is contained in:
zakorgyula 2016-10-07 12:42:40 +02:00
parent 2b4829b89a
commit 4ed461c6e5
6 changed files with 10 additions and 22 deletions

View file

@ -106,8 +106,8 @@ fn matches_filter(device: &BluetoothDevice, filter: &BluetoothScanfilter) -> boo
}
// Step 1.
if !filter.get_name().is_empty() {
if device.get_name().ok() != Some(filter.get_name().to_string()) {
if let Some(name) = filter.get_name() {
if device.get_name().ok() != Some(name.to_string()) {
return false;
}
}

View file

@ -25,7 +25,7 @@ impl ServiceUUIDSequence {
#[derive(Deserialize, Serialize)]
pub struct BluetoothScanfilter {
name: String,
name: Option<String>,
name_prefix: String,
services: ServiceUUIDSequence,
manufacturer_id: Option<u16>,
@ -33,7 +33,7 @@ pub struct BluetoothScanfilter {
}
impl BluetoothScanfilter {
pub fn new(name: String,
pub fn new(name: Option<String>,
name_prefix: String,
services: Vec<String>,
manufacturer_id: Option<u16>,
@ -48,8 +48,8 @@ impl BluetoothScanfilter {
}
}
pub fn get_name(&self) -> &str {
&self.name
pub fn get_name(&self) -> Option<&str> {
self.name.as_ref().map(|s| s.as_str())
}
pub fn get_name_prefix(&self) -> &str {
@ -69,12 +69,12 @@ impl BluetoothScanfilter {
}
pub fn is_empty_or_invalid(&self) -> bool {
(self.name.is_empty() &&
(self.name.is_none() &&
self.name_prefix.is_empty() &&
self.get_services().is_empty() &&
self.manufacturer_id.is_none() &&
self.service_data_uuid.is_empty()) ||
self.name.len() > MAX_NAME_LENGTH ||
self.get_name().unwrap_or("").len() > MAX_NAME_LENGTH ||
self.name_prefix.len() > MAX_NAME_LENGTH
}
}

View file

@ -217,9 +217,9 @@ fn canonicalize_filter(filter: &BluetoothRequestDeviceFilter) -> Fallible<Blueto
}
// Step 2.4.4.2.
name.to_string()
Some(name.to_string())
},
None => String::new(),
None => None,
};
// Step 2.4.5.

View file

@ -1,4 +0,0 @@
[name-empty-device-from-name-empty-filter.html]
type: testharness
[An empty name device can be obtained by empty name filter.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[name-empty-filter.html]
type: testharness
[A named device is not matched by a filter with an empty name.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[name-missing-device-from-name-empty-filter.html]
type: testharness
[An unnamed device can not be obtained by empty name filter.]
expected: FAIL