diff options
Diffstat (limited to 'ext')
-rw-r--r-- | ext/kv/codec.rs | 16 | ||||
-rw-r--r-- | ext/kv/lib.rs | 18 |
2 files changed, 14 insertions, 20 deletions
diff --git a/ext/kv/codec.rs b/ext/kv/codec.rs index b2acfdbc2..522c2e9bc 100644 --- a/ext/kv/codec.rs +++ b/ext/kv/codec.rs @@ -34,14 +34,6 @@ pub fn canonicalize_f64(n: f64) -> f64 { } pub fn encode_key(key: &Key) -> std::io::Result<Vec<u8>> { - // Disallow empty key - if key.0.is_empty() { - return Err(std::io::Error::new( - std::io::ErrorKind::InvalidInput, - "key should not be empty", - )); - } - let mut output: Vec<u8> = vec![]; for part in &key.0 { match part { @@ -73,14 +65,6 @@ pub fn encode_key(key: &Key) -> std::io::Result<Vec<u8>> { } pub fn decode_key(mut bytes: &[u8]) -> std::io::Result<Key> { - // Disallow empty key - if bytes.is_empty() { - return Err(std::io::Error::new( - std::io::ErrorKind::InvalidInput, - "key should not be empty", - )); - } - let mut key = Key(vec![]); while !bytes.is_empty() { let tag = bytes[0]; diff --git a/ext/kv/lib.rs b/ext/kv/lib.rs index 49a59af74..2d4bae6fc 100644 --- a/ext/kv/lib.rs +++ b/ext/kv/lib.rs @@ -102,8 +102,8 @@ type KvKey = Vec<AnyValue>; impl From<AnyValue> for KeyPart { fn from(value: AnyValue) -> Self { match value { - AnyValue::Bool(false) => KeyPart::True, - AnyValue::Bool(true) => KeyPart::False, + AnyValue::Bool(false) => KeyPart::False, + AnyValue::Bool(true) => KeyPart::True, AnyValue::Number(n) => KeyPart::Float(n), AnyValue::BigInt(n) => KeyPart::Int(n), AnyValue::String(s) => KeyPart::String(s), @@ -115,8 +115,8 @@ impl From<AnyValue> for KeyPart { impl From<KeyPart> for AnyValue { fn from(value: KeyPart) -> Self { match value { - KeyPart::True => AnyValue::Bool(false), - KeyPart::False => AnyValue::Bool(true), + KeyPart::False => AnyValue::Bool(false), + KeyPart::True => AnyValue::Bool(true), KeyPart::Float(n) => AnyValue::Number(n), KeyPart::Int(n) => AnyValue::BigInt(n), KeyPart::String(s) => AnyValue::String(s), @@ -499,6 +499,16 @@ where resource.db.clone() }; + for key in checks + .iter() + .map(|c| &c.0) + .chain(mutations.iter().map(|m| &m.0)) + { + if key.is_empty() { + return Err(type_error("key cannot be empty")); + } + } + let checks = checks .into_iter() .map(TryInto::try_into) |