mirror of
https://github.com/servo/servo.git
synced 2025-09-30 00:29:14 +01:00
net: Fix possible indexeddb key range singleton related panic (#38281)
If `.as_singleton()` was called on a range that had both lower and upper set as `None`, it would have panicked. Testing: Nothing seems to have changed Fixes: #37647 --------- Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
This commit is contained in:
parent
e649b9b91d
commit
f4bbdf8010
1 changed files with 16 additions and 1 deletions
|
@ -189,7 +189,7 @@ impl IndexedDBKeyRange {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_singleton(&self) -> bool {
|
pub fn is_singleton(&self) -> bool {
|
||||||
self.lower == self.upper && !self.lower_open && !self.upper_open
|
self.lower.is_some() && self.lower == self.upper && !self.lower_open && !self.upper_open
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_singleton(&self) -> Option<&IndexedDBKeyType> {
|
pub fn as_singleton(&self) -> Option<&IndexedDBKeyType> {
|
||||||
|
@ -200,6 +200,21 @@ impl IndexedDBKeyRange {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_as_singleton() {
|
||||||
|
let key = IndexedDBKeyType::Number(1.0);
|
||||||
|
let key2 = IndexedDBKeyType::Number(2.0);
|
||||||
|
let range = IndexedDBKeyRange::only(key.clone());
|
||||||
|
assert!(range.is_singleton());
|
||||||
|
assert!(range.as_singleton().is_some());
|
||||||
|
let range = IndexedDBKeyRange::new(Some(key), Some(key2.clone()), false, false);
|
||||||
|
assert!(!range.is_singleton());
|
||||||
|
assert!(range.as_singleton().is_none());
|
||||||
|
let full_range = IndexedDBKeyRange::new(None, None, false, false);
|
||||||
|
assert!(!full_range.is_singleton());
|
||||||
|
assert!(full_range.as_singleton().is_none());
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
pub enum AsyncReadOnlyOperation {
|
pub enum AsyncReadOnlyOperation {
|
||||||
/// Gets the value associated with the given key in the associated idb data
|
/// Gets the value associated with the given key in the associated idb data
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue