Skip to content

Commit

Permalink
Support searching for inscription IDs (#1294)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphjaph authored Jan 19, 2023
1 parent e41f84f commit 32d15e4
Showing 1 changed file with 19 additions and 0 deletions.
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

0 comments on commit 32d15e4

Please sign in to comment.