mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
f81f9ceb40
FileAndExt has now be completely rewritten and now works as may reasonably be expected. The test cases for: ReplaceExtension Filename FileAndExt now all pass. The problem was the way path.Base was being used. Firstly Base returns "." if the directory is empty, but it can also return "." for the current directory, or ".." for the parent directory, if these are the last elements in the path. Simply detecting the presence of a "." in the returned string and truncating before the "." does not therefore always result in a valid filename. Secondly, Base strips any trailing slashes making is more difficult to detect when the path does not end in a filename but in a directory name i.e. a no filename case. Not detecting this incorrectly results in the last directory name being returned as the filename. The code has been updated to take account of of both situations so that: 1) An empty string for both the filename and extension is returned if the path does not contain a filename (plus an optional extension). This includes both the empty path case, and the ends in a directory case. 2) If the path represents a filename with an extension then both the filename and the extension (minus any dots) are returned as non empty strings. 3) If the path represents a filename without an extension then filename will be returned as a non empty string (minus any dot) and the extension will be returned as an empty string. |
||
---|---|---|
.. | ||
content.go | ||
general.go | ||
general_test.go | ||
path.go | ||
path_test.go | ||
pygments.go | ||
url.go | ||
url_test.go |