Skip to content

Commit d8af231

Browse files
committed
Fix only lowercase plugin extensions being recognised
.esp, .esm, .esl and those plus .ghost suffixes are now matched case-insensitively.
1 parent 1043c21 commit d8af231

File tree

2 files changed

+32
-25
lines changed

2 files changed

+32
-25
lines changed

src/function/eval.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ fn evaluate_file_path(state: &State, file_path: &Path) -> Result<bool, Error> {
1616
}
1717

1818
fn is_match(game_type: GameType, regex: &Regex, file_name: &OsStr) -> bool {
19-
file_name
19+
normalise_file_name(game_type, file_name)
2020
.to_str()
21-
.map(|s| regex.is_match(normalise_file_name(game_type, s)))
21+
.map(|s| regex.is_match(s))
2222
.unwrap_or(false)
2323
}
2424

@@ -29,7 +29,8 @@ fn evaluate_regex(
2929
regex: &Regex,
3030
mut condition: impl FnMut() -> bool,
3131
) -> Result<bool, Error> {
32-
let dir_iterator = match read_dir(data_path.join(parent_path)) {
32+
let parent_path = data_path.join(parent_path);
33+
let dir_iterator = match read_dir(&parent_path) {
3334
Ok(i) => i,
3435
Err(_) => return Ok(false),
3536
};

src/function/path.rs

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,22 @@ use crate::{GameType, State};
88
const GHOST_EXTENSION: &str = "ghost";
99
const GHOST_EXTENSION_WITH_PERIOD: &str = ".ghost";
1010

11-
fn is_unghosted_plugin_file_extension(game_type: GameType, extension: &str) -> bool {
12-
match extension {
13-
"esp" | "esm" => true,
14-
"esl" if game_type.supports_light_plugins() => true,
15-
_ => false,
16-
}
11+
fn is_unghosted_plugin_file_extension(game_type: GameType, extension: &OsStr) -> bool {
12+
extension.eq_ignore_ascii_case("esp")
13+
|| extension.eq_ignore_ascii_case("esm")
14+
|| (game_type.supports_light_plugins() && extension.eq_ignore_ascii_case("esl"))
1715
}
1816

1917
fn has_unghosted_plugin_file_extension(game_type: GameType, path: &Path) -> bool {
20-
match path.extension().and_then(OsStr::to_str) {
18+
match path.extension() {
2119
Some(ext) => is_unghosted_plugin_file_extension(game_type, ext),
2220
_ => false,
2321
}
2422
}
2523

2624
pub fn has_plugin_file_extension(game_type: GameType, path: &Path) -> bool {
27-
match path.extension().and_then(OsStr::to_str) {
28-
Some(GHOST_EXTENSION) => path
25+
match path.extension() {
26+
Some(ext) if ext.eq_ignore_ascii_case(GHOST_EXTENSION) => path
2927
.file_stem()
3028
.map(|s| has_unghosted_plugin_file_extension(game_type, Path::new(s)))
3129
.unwrap_or(false),
@@ -45,10 +43,18 @@ fn add_ghost_extension(path: PathBuf) -> PathBuf {
4543
}
4644
}
4745

48-
pub fn normalise_file_name(game_type: GameType, name: &str) -> &str {
49-
if let Some(stem) = name.strip_suffix(GHOST_EXTENSION_WITH_PERIOD) {
50-
if has_unghosted_plugin_file_extension(game_type, Path::new(stem)) {
51-
return stem;
46+
pub fn normalise_file_name(game_type: GameType, name: &OsStr) -> &OsStr {
47+
let path = Path::new(name);
48+
if path
49+
.extension()
50+
.map(|s| s.eq_ignore_ascii_case(GHOST_EXTENSION))
51+
.unwrap_or(false)
52+
{
53+
// name ends in .ghost, trim it and then check the file extension.
54+
if let Some(stem) = path.file_stem() {
55+
if has_unghosted_plugin_file_extension(game_type, Path::new(stem)) {
56+
return stem;
57+
}
5258
}
5359
}
5460

@@ -89,7 +95,7 @@ mod tests {
8995

9096
#[test]
9197
fn is_unghosted_plugin_file_extension_should_be_true_for_esp_for_all_game_types() {
92-
let extension = "esp";
98+
let extension = OsStr::new("Esp");
9399

94100
assert!(is_unghosted_plugin_file_extension(
95101
GameType::Morrowind,
@@ -131,7 +137,7 @@ mod tests {
131137

132138
#[test]
133139
fn is_unghosted_plugin_file_extension_should_be_true_for_esm_for_all_game_types() {
134-
let extension = "esm";
140+
let extension = OsStr::new("Esm");
135141

136142
assert!(is_unghosted_plugin_file_extension(
137143
GameType::Morrowind,
@@ -173,7 +179,7 @@ mod tests {
173179

174180
#[test]
175181
fn is_unghosted_plugin_file_extension_should_be_true_for_esl_for_tes5se_tes5vr_fo4_and_fo4vr() {
176-
let extension = "esl";
182+
let extension = OsStr::new("Esl");
177183

178184
assert!(is_unghosted_plugin_file_extension(
179185
GameType::SkyrimSE,
@@ -195,7 +201,7 @@ mod tests {
195201

196202
#[test]
197203
fn is_unghosted_plugin_file_extension_should_be_false_for_esl_for_tes3_to_5_fo3_and_fonv() {
198-
let extension = "esl";
204+
let extension = OsStr::new("Esl");
199205

200206
assert!(!is_unghosted_plugin_file_extension(
201207
GameType::Morrowind,
@@ -221,7 +227,7 @@ mod tests {
221227

222228
#[test]
223229
fn is_unghosted_plugin_file_extension_should_be_false_for_ghost_for_all_game_types() {
224-
let extension = "ghost";
230+
let extension = OsStr::new("Ghost");
225231

226232
assert!(!is_unghosted_plugin_file_extension(
227233
GameType::Morrowind,
@@ -263,7 +269,7 @@ mod tests {
263269

264270
#[test]
265271
fn is_unghosted_plugin_file_extension_should_be_false_for_non_esp_esm_esl_for_all_game_types() {
266-
let extension = "txt";
272+
let extension = OsStr::new("txt");
267273

268274
assert!(!is_unghosted_plugin_file_extension(
269275
GameType::Morrowind,
@@ -351,7 +357,7 @@ mod tests {
351357
fn has_plugin_file_extension_should_return_true_if_the_path_has_a_ghosted_plugin_extension() {
352358
assert!(has_plugin_file_extension(
353359
GameType::Skyrim,
354-
Path::new("plugin.esp.ghost")
360+
Path::new("plugin.esp.Ghost")
355361
));
356362
}
357363

@@ -368,15 +374,15 @@ mod tests {
368374
) {
369375
assert!(!has_plugin_file_extension(
370376
GameType::Skyrim,
371-
Path::new("plugin.bsa.ghost")
377+
Path::new("plugin.bsa.Ghost")
372378
));
373379
}
374380

375381
#[test]
376382
fn has_plugin_file_extension_should_return_false_if_the_path_has_only_ghost_extension() {
377383
assert!(!has_plugin_file_extension(
378384
GameType::Skyrim,
379-
Path::new("plugin.ghost")
385+
Path::new("plugin.Ghost")
380386
));
381387
}
382388

0 commit comments

Comments
 (0)