Skip to content

Commit 3c2311b

Browse files
authored
fix(BIC-1999): fix cblite version (#9)
It used to return "3.0.17\0", which created problems
1 parent 78c5ae1 commit 3c2311b

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ use self::c_api::{
5454
};
5555
#[cfg(target_os = "android")]
5656
use self::c_api::{CBLError, CBLInitContext, CBL_Init};
57-
#[cfg(target_os = "android")]
5857
use std::ffi::CStr;
5958

6059
//////// RE-EXPORT:
@@ -121,7 +120,11 @@ impl Drop for ListenerToken {
121120
//////// MISC. API FUNCTIONS
122121

123122
pub fn couchbase_lite_c_version() -> String {
124-
String::from_utf8_lossy(CBLITE_VERSION).to_string()
123+
CStr::from_bytes_with_nul(CBLITE_VERSION)
124+
.unwrap_or_default()
125+
.to_str()
126+
.unwrap_or_default()
127+
.to_string()
125128
}
126129

127130
/** Returns the total number of Couchbase Lite objects. Useful for leak checking. */

tests/lib_test.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![cfg(test)]
2+
3+
extern crate couchbase_lite;
4+
5+
use couchbase_lite::*;
6+
7+
#[test]
8+
fn couchbase_lite_c_version_test() {
9+
assert_eq!(couchbase_lite_c_version(), "3.0.17".to_string());
10+
}

0 commit comments

Comments
 (0)