Lowercase page names before lookup (#227)

This commit is contained in:
Danilo Bargen 2021-12-05 14:31:03 +01:00 committed by GitHub
commit 023a9d2079
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View file

@ -493,7 +493,10 @@ fn main() {
// Show command from cache
if !args.command.is_empty() {
let command = args.command.join("-");
// Note: According to the TLDR client spec, page names must be transparently
// lowercased before lookup:
// https://github.com/tldr-pages/tldr/blob/main/CLIENT-SPECIFICATION.md#page-names
let command = args.command.join("-").to_lowercase();
let languages = args
.language

View file

@ -690,3 +690,22 @@ fn test_pager_warning() {
.success()
.stderr(contains("pager flag not available on Windows"));
}
/// Ensure that page lookup is case insensitive, so a page lookup for `eyed3`
/// and `eyeD3` should return the same page.
#[test]
fn test_lowercased_page_lookup() {
let testenv = TestEnv::new();
// Lookup `eyed3`, initially fails
testenv.command().args(["eyed3"]).assert().failure();
// Add entry
testenv.add_entry("eyed3", "contents");
// Lookup `eyed3` again
testenv.command().args(["eyed3"]).assert().success();
// Lookup `eyeD3`, should succeed as well
testenv.command().args(["eyeD3"]).assert().success();
}