better-files icon indicating copy to clipboard operation
better-files copied to clipboard

changeExtensionTo does not account for multiple dots in file name

Open pr0me opened this issue 1 year ago • 0 comments

The changeExtensionTo method (part of better.files.File) splits file names on the first occurrence of a dot and hence will incorrectly rename any file with multiple extensions.

I confirmed the bug by running the following example:

val test_file_0 = File("./xx.js.md")
val altered_0 = test_file_0.changeExtensionTo(".js")
logger.error(s"TEST 0: ${test_file_0} -> ${altered_0}")
val test_file_1 = File("./xx.md.md")
val altered_1 = test_file_0.changeExtensionTo(".js")
logger.error(s"TEST 1: ${test_file_1} -> ${altered_1}")

will result in

TEST 0: ./xx.js.md -> ./xx.js
TEST 1: ./xx.md.md -> ./xx.js

meaning that is also not only due to the extension and the replacement being the same.

System information:

  • OS: Linux pop-os 6.0.12-76060006-generic 22.04
  • javac 11.0.17

pr0me avatar Apr 30 '23 13:04 pr0me