Skip to content

Commit b1e1b37

Browse files
committed
- patched autocomplete when multiple programs have the same prefixes
- added .htaccess protection for the library
1 parent 3ba52bd commit b1e1b37

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

Diff for: commandline/library/.htaccess

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Deny from all

Diff for: commandline/library/lCommand.php

+23-1
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,30 @@ static function getAutoCompleteFor($input){
2323
array_push($all, basename($f));
2424
}
2525
asort($all);
26+
$candidates = [];
2627
foreach($all as $a){
27-
if(substr( $a, 0, strlen($input) ) == $input) return str_replace($input, "", $a);
28+
if(substr( $a, 0, strlen($input) ) == $input){
29+
$candidates[] = str_replace($input, "", $a);
30+
}
31+
}
32+
if(count($candidates)>0){
33+
$suggestion = "";
34+
$smallestLengt = array_reduce($candidates, function($carry, $item){
35+
return (strlen($item)<$carry or $carry===-1) ? strlen($item) : $carry;
36+
}, -1);
37+
$charAtPositionInAllSuggestionsSame = true;
38+
for($i=0; $i<$smallestLengt; $i++){
39+
$charAtPosition = $candidates[0][$i];
40+
foreach($candidates as $c){
41+
if($c[$i]!==$charAtPosition) $charAtPositionInAllSuggestionsSame = false;
42+
}
43+
if(!$charAtPositionInAllSuggestionsSame){
44+
return $suggestion;
45+
}else{
46+
$suggestion .= $charAtPosition;
47+
}
48+
}
49+
return $suggestion;
2850
}
2951
return null;
3052
}

0 commit comments

Comments
 (0)