Skip to content

Commit

Permalink
Accepting empty deviceName, when requesting a BluetoothDevice.
Browse files Browse the repository at this point in the history
  • Loading branch information
zakorgy committed Nov 4, 2016
1 parent 2b4829b commit 4ed461c
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 22 deletions.
4 changes: 2 additions & 2 deletions components/bluetooth/lib.rs
Expand Up @@ -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;
}
}
Expand Down
12 changes: 6 additions & 6 deletions components/bluetooth_traits/scanfilter.rs
Expand Up @@ -25,15 +25,15 @@ impl ServiceUUIDSequence {

#[derive(Deserialize, Serialize)]
pub struct BluetoothScanfilter {
name: String,
name: Option<String>,
name_prefix: String,
services: ServiceUUIDSequence,
manufacturer_id: Option<u16>,
service_data_uuid: String,
}

impl BluetoothScanfilter {
pub fn new(name: String,
pub fn new(name: Option<String>,
name_prefix: String,
services: Vec<String>,
manufacturer_id: Option<u16>,
Expand All @@ -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 {
Expand All @@ -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
}
}
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/bluetooth.rs
Expand Up @@ -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.
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 4ed461c

Please sign in to comment.