From 252859e63a1f41d79899d289da763b973df6a395 Mon Sep 17 00:00:00 2001 From: mmussomele Date: Sat, 16 May 2015 23:53:08 -0700 Subject: [PATCH] fixed accidentally correcting to some directories with short name length --- thefuck/rules/cd_correction.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/thefuck/rules/cd_correction.py b/thefuck/rules/cd_correction.py index 96bee90c..98a2655a 100644 --- a/thefuck/rules/cd_correction.py +++ b/thefuck/rules/cd_correction.py @@ -76,7 +76,8 @@ def get_new_command(command, settings): cwd = os.path.split(cwd)[0] continue best_match = min(_get_sub_dirs(cwd), key=lambda x: _dam_lev_dist(directory, x)) - if _dam_lev_dist(directory, best_match) > MAX_ALLOWED_STR_DIST: + best_dist = _dam_lev_dist(directory, best_match) + if best_dist > MAX_ALLOWED_STR_DIST or best_dist >= len(best_match): return cd_mkdir.get_new_command(command, settings) else: cwd = os.path.join(cwd, best_match)