Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search bar supports inscription id #1294

Merged
merged 1 commit into from
Jan 19, 2023
Merged
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
19 changes: 19 additions & 0 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ impl Server {
lazy_static! {
static ref HASH: Regex = Regex::new(r"^[[:xdigit:]]{64}$").unwrap();
static ref OUTPOINT: Regex = Regex::new(r"^[[:xdigit:]]{64}:\d+$").unwrap();
static ref INSCRIPTION_ID: Regex = Regex::new(r"^[[:xdigit:]]{64}i\d+$").unwrap();
}

let query = query.trim();
Expand All @@ -547,6 +548,8 @@ impl Server {
}
} else if OUTPOINT.is_match(query) {
Ok(Redirect::to(&format!("/output/{query}")))
} else if INSCRIPTION_ID.is_match(query) {
Ok(Redirect::to(&format!("/inscription/{query}")))
} else {
Ok(Redirect::to(&format!("/sat/{query}")))
}
Expand Down Expand Up @@ -1183,6 +1186,14 @@ mod tests {
TestServer::new().assert_redirect("/search?query=0", "/sat/0");
}

#[test]
fn search_by_query_returns_inscription() {
TestServer::new().assert_redirect(
"/search?query=0000000000000000000000000000000000000000000000000000000000000000i0",
"/inscription/0000000000000000000000000000000000000000000000000000000000000000i0",
);
}

#[test]
fn search_is_whitespace_insensitive() {
TestServer::new().assert_redirect("/search/ 0 ", "/sat/0");
Expand Down Expand Up @@ -1217,6 +1228,14 @@ mod tests {
);
}

#[test]
fn search_for_inscription_id_returns_inscription() {
TestServer::new().assert_redirect(
"/search/0000000000000000000000000000000000000000000000000000000000000000i0",
"/inscription/0000000000000000000000000000000000000000000000000000000000000000i0",
);
}

#[test]
fn http_to_https_redirect_with_path() {
TestServer::new_with_args(&[], &["--redirect-http-to-https", "--https"]).assert_redirect(
Expand Down