Skip to content

Fixes #13274: Allow cygwin-paths on Windows #13297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
382071f
feat: add method to convert Cygwin-style paths to Windows format
kvitorr Jun 10, 2025
93087c9
feat: apply the convertCygwinPathToWinds on the path to prevent the I…
kvitorr Jun 10, 2025
568bb34
Merge branch 'main' into fix-for-issue-13274
kvitorr Jun 10, 2025
2f87d70
fix: remove FileUtil method
kvitorr Jun 10, 2025
0f5cce4
Merge branch 'fix-for-issue-13274' of https://github.com/kvitorr/jabr…
kvitorr Jun 10, 2025
c343086
feat: add Cygwin file path /mtn/
kvitorr Jun 10, 2025
773a4eb
feat: add test to Cygwin file path /mtn/
kvitorr Jun 10, 2025
2334c9e
feat: add entry on CHANGELOG.md and weave the method into JabKit.
kvitorr Jun 10, 2025
37c6203
feat: remove convertCygwinPathToWindows
kvitorr Jun 12, 2025
19d92f3
feat: create converters and add new package to java modules
kvitorr Jun 12, 2025
e6aea3b
feat: apply converters to --inputs and --outputs
kvitorr Jun 12, 2025
025a2eb
style: remove blank space
kvitorr Jun 12, 2025
70cc464
Merge branch 'JabRef:main' into fix-for-issue-13274
kvitorr Jun 12, 2025
249f38f
feat: change the DataType from String and File to Path
kvitorr Jun 14, 2025
5241f3c
feat: remove code duplication
kvitorr Jun 14, 2025
385ab81
fix: correct the style
kvitorr Jun 14, 2025
2c40476
feat: create a new method to remove code duplication, create constant…
kvitorr Jun 14, 2025
fde43a6
feat: correct the unit tests to the changes made in the class
kvitorr Jun 14, 2025
35a84ec
Merge branch 'fix-for-issue-13274' of https://github.com/kvitorr/jabr…
kvitorr Jun 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions jablib/src/main/java/org/jabref/logic/util/io/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.jabref.logic.FilePreferences;
import org.jabref.logic.citationkeypattern.BracketedPattern;
import org.jabref.logic.layout.format.RemoveLatexCommandsFormatter;
import org.jabref.logic.os.OS;
import org.jabref.logic.util.StandardFileType;
import org.jabref.model.database.BibDatabase;
import org.jabref.model.database.BibDatabaseContext;
Expand Down Expand Up @@ -589,4 +590,34 @@ public static String shortenFileName(String fileName, Integer maxLength) {
public static boolean isCharLegal(char c) {
return Arrays.binarySearch(ILLEGAL_CHARS, c) < 0;
}

/**
* Converts a Cygwin-style file path to a Windows-style path, if the operating system is Windows.
*
* Supported formats:
* - /cygdrive/c/Users/... → C:\Users\...
* - /c/Users/... → C:\Users\...
*
* @param filePath the input file path
* @return the converted path if running on Windows and path is in Cygwin format; otherwise, returns the original path
*/
public static String convertCygwinPathToWindows(String filePath) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return Path object

if (!OS.WINDOWS || filePath == null) {
return filePath;
}

if (filePath.startsWith("/cygdrive/") && filePath.length() > 10) {
String driveLetter = filePath.substring(10, 11).toUpperCase();
String path = filePath.substring(11).replace("/", "\\\\");
return driveLetter + ":" + path;
}

if (filePath.matches("^/[a-zA-Z]/.*")) {
String driveLetter = filePath.substring(1, 2).toUpperCase();
String path = filePath.substring(2).replace("/", "\\\\");
return driveLetter + ":" + path;
}

return filePath;
}
}
15 changes: 15 additions & 0 deletions jablib/src/test/java/org/jabref/logic/util/io/FileUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
Expand Down Expand Up @@ -518,4 +519,18 @@ void illegalPaths(String fileName) {
void shortenFileName(String expected, String fileName, Integer maxLength) {
assertEquals(expected, FileUtil.shortenFileName(fileName, maxLength));
}

@EnabledOnOs(value = org.junit.jupiter.api.condition.OS.WINDOWS)
@ParameterizedTest
@ValueSource(strings = {"/c/Users/username/Downloads/test.bib", "/cygdrive/c/Users/username/Downloads/test.bib"})
void convertCygwinPathToWindowsShouldConvertToWindowsFormatWhenRunningOnWindows(String filePath) {
assertEquals("C:\\\\Users\\\\username\\\\Downloads\\\\test.bib", FileUtil.convertCygwinPathToWindows(filePath));
}

@DisabledOnOs(value = org.junit.jupiter.api.condition.OS.WINDOWS, disabledReason = "Test in others operational systems")
@ParameterizedTest
@ValueSource(strings = {"/home/username/Downloads/test.bib"})
void convertCygwinPathToWindowsShouldReturnOriginalFilePathWhenRunningOnWindows(String filePath) {
assertEquals(filePath, FileUtil.convertCygwinPathToWindows(filePath));
}
}
Loading