Skip to content

Commit 794eb47

Browse files
authored
[fix] Quickwit panics while attempting to parse index_uri (#3692)
This PR also normalize the protocol. For instance postgres:// becomes postgresql after dserialization + serialization.
1 parent 90c59a2 commit 794eb47

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

quickwit/quickwit-common/src/uri.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,10 @@ impl Uri {
275275
bail!("Failed to parse empty URI.");
276276
}
277277
let (protocol, mut path) = match uri_str.split_once(PROTOCOL_SEPARATOR) {
278-
None => (Protocol::File.as_str(), uri_str.to_string()),
279-
Some((protocol, path)) => (protocol, path.to_string()),
278+
None => (Protocol::File, uri_str.to_string()),
279+
Some((protocol, path)) => (Protocol::from_str(protocol)?, path.to_string()),
280280
};
281-
if protocol == Protocol::File.as_str() {
281+
if protocol == Protocol::File {
282282
if path.starts_with('~') {
283283
// We only accept `~` (alias to the home directory) and `~/path/to/something`.
284284
// If there is something following the `~` that is not `/`, we bail.
@@ -306,7 +306,7 @@ impl Uri {
306306
}
307307
Ok(Self {
308308
uri: format!("{protocol}{PROTOCOL_SEPARATOR}{path}"),
309-
protocol_idx: protocol.len(),
309+
protocol_idx: protocol.as_str().len(),
310310
})
311311
}
312312
}
@@ -486,6 +486,13 @@ mod tests {
486486
Uri::from_str("azure://account/container/homer/docs/../dognuts").unwrap(),
487487
"azure://account/container/homer/docs/../dognuts"
488488
);
489+
490+
assert_eq!(
491+
Uri::from_str("http://localhost:9000/quickwit")
492+
.unwrap_err()
493+
.to_string(),
494+
"Unknown URI protocol `http`."
495+
);
489496
}
490497

491498
#[test]

quickwit/quickwit-config/src/node_config/serialize.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ mod tests {
455455
assert_eq!(config.data_dir_path, Path::new("/opt/quickwit/data"));
456456
assert_eq!(
457457
config.metastore_uri,
458-
"postgres://username:password@host:port/db"
458+
"postgresql://username:password@host:port/db"
459459
);
460460
assert_eq!(config.default_index_root_uri, "s3://quickwit-indexes");
461461

@@ -618,7 +618,7 @@ mod tests {
618618
env_vars.insert("QW_DATA_DIR".to_string(), "test-data-dir".to_string());
619619
env_vars.insert(
620620
"QW_METASTORE_URI".to_string(),
621-
"postgres://test-user:test-password@test-host:4321/test-db".to_string(),
621+
"postgresql://test-user:test-password@test-host:4321/test-db".to_string(),
622622
);
623623
env_vars.insert(
624624
"QW_DEFAULT_INDEX_ROOT_URI".to_string(),
@@ -672,7 +672,7 @@ mod tests {
672672
);
673673
assert_eq!(
674674
config.metastore_uri,
675-
"postgres://test-user:test-password@test-host:4321/test-db"
675+
"postgresql://test-user:test-password@test-host:4321/test-db"
676676
);
677677
assert_eq!(config.default_index_root_uri, "s3://quickwit-indexes/prod");
678678
}
@@ -695,7 +695,7 @@ mod tests {
695695
assert_eq!(config.node_id, "node-1");
696696
assert_eq!(
697697
config.metastore_uri,
698-
"postgres://username:password@host:port/db"
698+
"postgresql://username:password@host:port/db"
699699
);
700700
}
701701

@@ -715,7 +715,7 @@ mod tests {
715715
.unwrap();
716716
assert_eq!(
717717
config.metastore_uri,
718-
"postgres://username:password@host:port/db"
718+
"postgresql://username:password@host:port/db"
719719
);
720720
assert_eq!(config.indexer_config, IndexerConfig::default());
721721
assert_eq!(config.searcher_config, SearcherConfig::default());

0 commit comments

Comments
 (0)