///|
test "pattern plain prefix matches" {
assert_true(pattern_matches("/a", "/abc"))
}
///|
test "pattern plain prefix does not match different prefix" {
assert_false(pattern_matches("/a", "/b"))
}
///|
test "pattern star matches many chars" {
assert_true(pattern_matches("/a*c", "/abbbbbc"))
}
///|
test "pattern star matches zero chars" {
assert_true(pattern_matches("/a*c", "/ac"))
}
///|
test "pattern dollar requires exact end" {
assert_true(pattern_matches("/a$", "/a"))
assert_false(pattern_matches("/a$", "/ab"))
}
///|
test "pattern specificity ignores star and dollar" {
assert_int_eq(pattern_specificity("/a*b$"), 3)
}
///|
test "percent encoded unreserved normalizes in path" {
match normalize_path_for_match("/a%62") {
Ok(v) => assert_str_eq(v, "/ab")
Err(e) => fail(e.to_display())
}
}
///|
test "percent encoded reserved stays encoded uppercase" {
match normalize_path_for_match("/a%2fb") {
Ok(v) => assert_str_eq(v, "/a%2Fb")
Err(e) => fail(e.to_display())
}
}
///|
test "raw non-ASCII path is encoded as UTF-8 octets" {
match normalize_path_for_match("/ツ") {
Ok(v) => assert_str_eq(v, "/%E3%83%84")
Err(e) => fail(e.to_display())
}
}
///|
test "raw Unicode rule matches percent encoded URI path" {
let f = unwrap_file(parse_robots("User-agent: *\nDisallow: /ツ\n"))
assert_false(can_fetch(f, "bot", "/%E3%83%84"))
}
///|
test "percent encoded Unicode rule matches raw URI path" {
let f = unwrap_file(
parse_robots("User-agent: *\nDisallow: /%E7%A7%81%E4%BA%BA/\n"),
)
assert_false(can_fetch(f, "bot", "/私人/index"))
}
///|
test "percent encoded star is not wildcard" {
let f = unwrap_file(parse_robots("User-agent: *\nDisallow: /a%2A\n"))
assert_false(can_fetch(f, "bot", "/a%2A"))
assert_true(can_fetch(f, "bot", "/abc"))
}
///|
test "percent encoded dollar is not end marker" {
let f = unwrap_file(parse_robots("User-agent: *\nDisallow: /a%24\n"))
assert_false(can_fetch(f, "bot", "/a%24"))
assert_true(can_fetch(f, "bot", "/a"))
}
///|
test "malformed percent path returns error" {
expect_err_kind(normalize_path_for_match("/a%"), InvalidPercentEncoding)
}
///|
test "UTF-8 path matching is stable" {
let f = unwrap_file(parse_robots("User-agent: *\nDisallow: /私人/\n"))
assert_false(can_fetch(f, "bot", "/私人/index"))
}
///|
test "pattern specificity counts percent triplet as one octet" {
assert_int_eq(pattern_specificity("/%E3%83%84"), 4)
}