Fixes #24412
This commit is contained in:
parent
b7788c063e
commit
a58bd458f7
|
@ -92,12 +92,12 @@ public class Files {
|
||||||
if(toFix.startsWith("\\."))
|
if(toFix.startsWith("\\."))
|
||||||
toFix=toFix.replaceFirst("\\.","_");
|
toFix=toFix.replaceFirst("\\.","_");
|
||||||
String extension="";
|
String extension="";
|
||||||
if(toFix.contains(".")) {
|
int extensionIndex=toFix.lastIndexOf(".");
|
||||||
|
if(extensionIndex>0) {
|
||||||
//preserve extension
|
//preserve extension
|
||||||
int index=toFix.indexOf(".");
|
extension=toFix.substring(extensionIndex);
|
||||||
extension=toFix.substring(index);
|
|
||||||
//only escape before extension
|
//only escape before extension
|
||||||
toFix=toFix.substring(0,toFix.indexOf("."));
|
toFix=toFix.substring(0,extensionIndex);
|
||||||
}
|
}
|
||||||
return toFix.toLowerCase().
|
return toFix.toLowerCase().
|
||||||
replaceAll("[\\-\\*\\+\\/\\\\ \\[\\]\\(\\)\\.\\\"\\:\\;\\|\\=]","_")+extension.toLowerCase();
|
replaceAll("[\\-\\*\\+\\/\\\\ \\[\\]\\(\\)\\.\\\"\\:\\;\\|\\=]","_")+extension.toLowerCase();
|
||||||
|
|
|
@ -6,6 +6,8 @@ import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -18,11 +20,17 @@ public class FilesTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNames(){
|
public void testNames(){
|
||||||
for(String name : baseFolder.list()){
|
|
||||||
|
ArrayList<String> toTestStrings=new ArrayList<>(Arrays.asList(baseFolder.list()));
|
||||||
|
toTestStrings.add("e. gna_topografia_timponedellamotta.qmd");
|
||||||
|
|
||||||
|
for(String name : toTestStrings){
|
||||||
if(name.contains(".")) {
|
if(name.contains(".")) {
|
||||||
String originalExtension = name.substring(name.indexOf("."));
|
int extensionIndex = name.lastIndexOf(".");
|
||||||
|
String originalExtension = extensionIndex>0?name.substring(extensionIndex):null;
|
||||||
String obtained = Files.fixFilename(name);
|
String obtained = Files.fixFilename(name);
|
||||||
log.info(name + "->" + obtained + "[" + originalExtension + "]");
|
log.info(name + "->" + obtained + "[" + originalExtension + "]");
|
||||||
|
if(originalExtension!=null)
|
||||||
assertTrue(obtained.endsWith(originalExtension));
|
assertTrue(obtained.endsWith(originalExtension));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue