mirror of
https://git.pumpin.online/funkpower/catena.git
synced 2026-11-24 19:32:56 +00:00
bibclean: name a web address saved as a title, and leave it alone
url_title (weight 4): a title that is an http, file or www address. The underscore repair no longer runs on an address or a path, where it turned "stranger_than_fiction.htm" into "stranger than fiction.htm" and left something that was neither a title nor an address.
This commit is contained in:
3 files changed
+30
No files matched your search
@@ -218,8 +218,13 @@ pub fn clean(book: &Book) -> Cleaned {
|
||||
// Underscores first: a title mangled by a filename may also be shouting,
|
||||
// and title-casing it before the underscores come out would case the
|
||||
// format suffix as though it were a word.
|
||||
// Not in an address or a path, where the underscores are the name and
|
||||
// taking them out leaves something that is neither title nor address.
|
||||
if let Some(title) = cleaned.title.clone()
|
||||
&& reasons.iter().any(|reason| reason == "underscore_title")
|
||||
&& !reasons
|
||||
.iter()
|
||||
.any(|reason| reason == "url_title" || reason == "path_title")
|
||||
{
|
||||
let fixed = fix::clean_underscores(&title);
|
||||
if fixed != title {
|
||||
@@ -481,6 +486,22 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_address_is_named_and_left_alone() {
|
||||
for title in [
|
||||
"http://www.voxfux.com/features/stranger_than_fiction.htm",
|
||||
"file://D:\\Books\\white_paper",
|
||||
"www.example.org/some_page",
|
||||
] {
|
||||
let cleaned = clean(&book(title, "Someone"));
|
||||
assert_eq!(cleaned.book.title.as_deref(), Some(title), "{title}");
|
||||
assert!(
|
||||
cleaned.reasons.iter().any(|reason| reason == "url_title"),
|
||||
"{title}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_shouting_title_is_cased_and_the_change_is_recorded() {
|
||||
let cleaned = clean(&book("THE HUMAN CONDITION", "Arendt, Hannah"));
|
||||
|
||||
Reference in new issue
Block a user