Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions libsql-server/src/connection/dump/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ impl<W: Write> DumpState<W> {
let table_str = std::str::from_utf8(table)?;
writeln!(
self.writer,
"INSERT INTO sqlite_schema(type,name,tbl_name,rootpage,sql) VALUES('table','{}','{}',0,'{}');",
"INSERT INTO sqlite_schema(type,name,tbl_name,rootpage,sql)VALUES('table','{}','{}',0,{});",
table_str,
table_str,
std::str::from_utf8(sql)?
Escaped(std::str::from_utf8(sql)?)
)?;
continue;
} else {
Expand Down Expand Up @@ -536,4 +536,25 @@ mod test {

insta::assert_snapshot!(std::str::from_utf8(&out).unwrap());
}

#[test]
fn virtual_table_sql_escaping() {
let tmp = tempdir().unwrap();
let mut conn = Connection::open(tmp.path().join("data")).unwrap();

conn.execute(r#"CREATE VIRTUAL TABLE test_fts USING fts5(content)"#, ())
.unwrap();

conn.execute(
r#"CREATE VIRTUAL TABLE test_vocab USING fts5vocab(test_fts, 'row')"#,
(),
)
.unwrap();

let mut out = Vec::new();
export_dump(&mut conn, &mut out, false).unwrap();
let dump_output = std::str::from_utf8(&out).unwrap();

assert!(dump_output.contains("''row''"));
}
}
Loading