Auto merge of #15366 - szeged:name-filter-length, r=nox

Remove the 29 byte limitation, when requesting bluetooth devices

<!-- Please describe your changes on the following line: -->

Remove the 29 byte limit when calling `requestDevice` using a `name` or `namePrefix`. The following discussion is about this by the specification writers: https://bugs.chromium.org/p/chromium/issues/detail?id=653718.
Related tests also got removed.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] There are tests for these changes

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15366)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-02-03 04:15:34 -08:00 committed by GitHub
commit f5e35179d4
6 changed files with 1 additions and 98 deletions

View file

@ -13,7 +13,7 @@ use dom::bindings::codegen::Bindings::BluetoothBinding::{self, BluetoothDataFilt
use dom::bindings::codegen::Bindings::BluetoothBinding::{BluetoothMethods, RequestDeviceOptions}; use dom::bindings::codegen::Bindings::BluetoothBinding::{BluetoothMethods, RequestDeviceOptions};
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull; use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
use dom::bindings::codegen::UnionTypes::StringOrUnsignedLong; use dom::bindings::codegen::UnionTypes::StringOrUnsignedLong;
use dom::bindings::error::Error::{self, Network, NotFound, Security, Type}; use dom::bindings::error::Error::{self, Network, Security, Type};
use dom::bindings::error::Fallible; use dom::bindings::error::Fallible;
use dom::bindings::js::{JS, Root}; use dom::bindings::js::{JS, Root};
use dom::bindings::refcounted::{Trusted, TrustedPromise}; use dom::bindings::refcounted::{Trusted, TrustedPromise};
@ -40,11 +40,6 @@ const MANUFACTURER_DATA_ERROR: &'static str = "'manufacturerData', if present, m
const MASK_LENGTH_ERROR: &'static str = "`mask`, if present, must have the same length as `dataPrefix`."; const MASK_LENGTH_ERROR: &'static str = "`mask`, if present, must have the same length as `dataPrefix`.";
// 248 is the maximum number of UTF-8 code units in a Bluetooth Device Name. // 248 is the maximum number of UTF-8 code units in a Bluetooth Device Name.
const MAX_DEVICE_NAME_LENGTH: usize = 248; const MAX_DEVICE_NAME_LENGTH: usize = 248;
// A device name can never be longer than 29 bytes.
// An advertising packet is at most 31 bytes long.
// The length and identifier of the length field take 2 bytes.
// That leaves 29 bytes for the name.
const MAX_FILTER_NAME_LENGTH: usize = 29;
const NAME_PREFIX_ERROR: &'static str = "'namePrefix', if present, must be nonempty."; const NAME_PREFIX_ERROR: &'static str = "'namePrefix', if present, must be nonempty.";
const NAME_TOO_LONG_ERROR: &'static str = "A device name can't be longer than 248 bytes."; const NAME_TOO_LONG_ERROR: &'static str = "A device name can't be longer than 248 bytes.";
const SERVICE_DATA_ERROR: &'static str = "'serviceData', if present, must be non-empty to filter devices."; const SERVICE_DATA_ERROR: &'static str = "'serviceData', if present, must be non-empty to filter devices.";
@ -311,9 +306,6 @@ fn canonicalize_filter(filter: &BluetoothLEScanFilterInit) -> Fallible<Bluetooth
if name.len() > MAX_DEVICE_NAME_LENGTH { if name.len() > MAX_DEVICE_NAME_LENGTH {
return Err(Type(NAME_TOO_LONG_ERROR.to_owned())); return Err(Type(NAME_TOO_LONG_ERROR.to_owned()));
} }
if name.len() > MAX_FILTER_NAME_LENGTH {
return Err(NotFound);
}
// Step 4.2. // Step 4.2.
Some(name.to_string()) Some(name.to_string())
@ -331,9 +323,6 @@ fn canonicalize_filter(filter: &BluetoothLEScanFilterInit) -> Fallible<Bluetooth
if name_prefix.len() > MAX_DEVICE_NAME_LENGTH { if name_prefix.len() > MAX_DEVICE_NAME_LENGTH {
return Err(Type(NAME_TOO_LONG_ERROR.to_owned())); return Err(Type(NAME_TOO_LONG_ERROR.to_owned()));
} }
if name_prefix.len() > MAX_FILTER_NAME_LENGTH {
return Err(NotFound);
}
// Step 5.2. // Step 5.2.
name_prefix.to_string() name_prefix.to_string()

View file

@ -7778,18 +7778,6 @@
"url": "/_mozilla/mozilla/bluetooth/requestDevice/canonicalizeFilter/max-length-for-device-name-namePrefix.html" "url": "/_mozilla/mozilla/bluetooth/requestDevice/canonicalizeFilter/max-length-for-device-name-namePrefix.html"
} }
], ],
"mozilla/bluetooth/requestDevice/canonicalizeFilter/max-length-for-name-in-adv-name.html": [
{
"path": "mozilla/bluetooth/requestDevice/canonicalizeFilter/max-length-for-name-in-adv-name.html",
"url": "/_mozilla/mozilla/bluetooth/requestDevice/canonicalizeFilter/max-length-for-name-in-adv-name.html"
}
],
"mozilla/bluetooth/requestDevice/canonicalizeFilter/max-length-for-name-in-adv-namePrefix.html": [
{
"path": "mozilla/bluetooth/requestDevice/canonicalizeFilter/max-length-for-name-in-adv-namePrefix.html",
"url": "/_mozilla/mozilla/bluetooth/requestDevice/canonicalizeFilter/max-length-for-name-in-adv-namePrefix.html"
}
],
"mozilla/bluetooth/requestDevice/canonicalizeFilter/no-arguments.html": [ "mozilla/bluetooth/requestDevice/canonicalizeFilter/no-arguments.html": [
{ {
"path": "mozilla/bluetooth/requestDevice/canonicalizeFilter/no-arguments.html", "path": "mozilla/bluetooth/requestDevice/canonicalizeFilter/no-arguments.html",
@ -7814,18 +7802,6 @@
"url": "/_mozilla/mozilla/bluetooth/requestDevice/canonicalizeFilter/unicode-max-length-for-device-name-namePrefix.html" "url": "/_mozilla/mozilla/bluetooth/requestDevice/canonicalizeFilter/unicode-max-length-for-device-name-namePrefix.html"
} }
], ],
"mozilla/bluetooth/requestDevice/canonicalizeFilter/unicode-max-length-for-name-in-adv-name.html": [
{
"path": "mozilla/bluetooth/requestDevice/canonicalizeFilter/unicode-max-length-for-name-in-adv-name.html",
"url": "/_mozilla/mozilla/bluetooth/requestDevice/canonicalizeFilter/unicode-max-length-for-name-in-adv-name.html"
}
],
"mozilla/bluetooth/requestDevice/canonicalizeFilter/unicode-max-length-for-name-in-adv-namePrefix.html": [
{
"path": "mozilla/bluetooth/requestDevice/canonicalizeFilter/unicode-max-length-for-name-in-adv-namePrefix.html",
"url": "/_mozilla/mozilla/bluetooth/requestDevice/canonicalizeFilter/unicode-max-length-for-name-in-adv-namePrefix.html"
}
],
"mozilla/bluetooth/requestDevice/canonicalizeFilter/unicode-valid-length-name-name.html": [ "mozilla/bluetooth/requestDevice/canonicalizeFilter/unicode-valid-length-name-name.html": [
{ {
"path": "mozilla/bluetooth/requestDevice/canonicalizeFilter/unicode-valid-length-name-name.html", "path": "mozilla/bluetooth/requestDevice/canonicalizeFilter/unicode-valid-length-name-name.html",

View file

@ -1,14 +0,0 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/_mozilla/mozilla/bluetooth/bluetooth-helpers.js"></script>
<script>
'use strict';
promise_test(t => {
let name_too_long = 'a'.repeat(30);
window.testRunner.setBluetoothMockDataSet(adapter_type.empty);
return promise_rejects(
t, 'NotFoundError', window.navigator.bluetooth.requestDevice({filters: [{name: name_too_long}]}),
'Device name longer than 29');
}, 'A device name longer than 29 must reject.');
</script>

View file

@ -1,14 +0,0 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/_mozilla/mozilla/bluetooth/bluetooth-helpers.js"></script>
<script>
'use strict';
promise_test(t => {
let name_too_long = 'a'.repeat(30);
window.testRunner.setBluetoothMockDataSet(adapter_type.empty);
return promise_rejects(
t, 'NotFoundError', window.navigator.bluetooth.requestDevice({filters: [{namePrefix: name_too_long}]}),
'Device name longer than 29');
}, 'A device name prefix longer than 29 must reject.');
</script>

View file

@ -1,17 +0,0 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/_mozilla/mozilla/bluetooth/bluetooth-helpers.js"></script>
<script>
'use strict';
promise_test(t => {
// \u2764's UTF-8 respresentation is 3 bytes long.
// 10 chars * 3 bytes/char = 30 bytes
let unicode_name = '\u2764'.repeat(10);
window.testRunner.setBluetoothMockDataSet(adapter_type.unicode_device);
return promise_rejects(
t, 'NotFoundError', window.navigator.bluetooth.requestDevice({filters: [{name: unicode_name}]}),
'Device name longer than 29 bytes');
}, 'Unicode string with utf8 representation between (29, 248] bytes in ' +
'\'name\' must throw NotFoundError.');
</script>

View file

@ -1,17 +0,0 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/_mozilla/mozilla/bluetooth/bluetooth-helpers.js"></script>
<script>
'use strict';
promise_test(t => {
// \u2764's UTF-8 respresentation is 3 bytes long.
// 10 chars * 3 bytes/char = 30 bytes
let unicode_name = '\u2764'.repeat(10);
window.testRunner.setBluetoothMockDataSet(adapter_type.unicode_device);
return promise_rejects(
t, 'NotFoundError', window.navigator.bluetooth.requestDevice({filters: [{namePrefix: unicode_name}]}),
'Device name longer than 29 bytes');
}, 'Unicode string with utf8 representation between (29, 248] bytes in ' +
'\'namePrefix\' must throw NotFoundError.');
</script>