Skip to content

Commit f053490

Browse files
committed
Avoid double slash edge case at file system root
Only a cosmetic issue, as `readfile('//.editorconfig')` works just fine.
1 parent 8f9d8cc commit f053490

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

plugin/sleuth.vim

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,15 +262,16 @@ function! s:DetectEditorConfig(absolute_path, ...) abort
262262
return [{}, '']
263263
endif
264264
let root = ''
265-
let tail = a:0 ? '/' . a:1 : '/.editorconfig'
265+
let tail = a:0 ? a:1 : '.editorconfig'
266266
let dir = fnamemodify(a:absolute_path, ':h')
267267
let previous_dir = ''
268268
let sections = []
269269
let overrides = get(g:, 'sleuth_editorconfig_overrides', {})
270270
while dir !=# previous_dir && dir !~# '^//\%([^/]\+/\=\)\=$'
271-
let read_from = get(overrides, dir . tail, get(overrides, dir, dir . tail))
272-
if type(read_from) == type('') && read_from !=# dir . tail && read_from !~# '^/\|^\a\+:\|^$'
273-
let read_from = simplify(dir . '/' . read_from)
271+
let head = substitute(dir, '/\=$', '/', '')
272+
let read_from = get(overrides, head . tail, get(overrides, head, head . tail))
273+
if type(read_from) == type('') && read_from !=# head . tail && read_from !~# '^/\|^\a\+:\|^$'
274+
let read_from = simplify(head . read_from)
274275
endif
275276
let ftime = type(read_from) == type('') ? getftime(read_from) : -1
276277
let [cachetime; econfig] = get(s:editorconfig_cache, read_from, [-1, {}, []])
@@ -282,7 +283,7 @@ function! s:DetectEditorConfig(absolute_path, ...) abort
282283
endif
283284
call extend(sections, econfig[1], 'keep')
284285
if get(econfig[0], 'root', [''])[0] ==? 'true'
285-
let root = dir
286+
let root = head
286287
break
287288
endif
288289
let previous_dir = dir
@@ -516,7 +517,7 @@ function! s:DetectHeuristics(into) abort
516517
return detected
517518
endif
518519
let dir = len(detected.path) ? fnamemodify(detected.path, ':h') : ''
519-
let root = len(detected.root) ? detected.root : dir ==# s:Slash(expand('~')) ? dir : fnamemodify(dir, ':h')
520+
let root = len(detected.root) ? fnamemodify(detected.root, ':h') : dir ==# s:Slash(expand('~')) ? dir : fnamemodify(dir, ':h')
520521
if detected.bufname =~# '^\a\a\+:' || root ==# '.' || !isdirectory(root)
521522
let dir = ''
522523
endif

0 commit comments

Comments
 (0)