exploration icon indicating copy to clipboard operation
exploration copied to clipboard

Bug: Handle Both Windows and UNIX Path Separators

Open winner106 opened this issue 10 months ago • 1 comments

Description:

The current SEP_NEGATE_RE regular expression only supports UNIX-style paths with the / separator. However, it fails to handle Windows-style paths, which use the \ separator. This bug causes the split function to incorrectly split Windows paths.

Steps to Reproduce:

  1. Run the split function with a Windows path, for example:
    split("C:\\Users\\Administrator\\Documents\\KKNote\\Notes.md");
    
  2. The function does not properly split the path and returns incorrect results.

Expected Behavior:

The split function should correctly handle both UNIX-style and Windows-style paths. It should split the path by both / and \ separators, and return the correct path components.

Solution:

  • Modify the SEP_NEGATE_RE regular expression to handle both / and \ as valid path separators:
    const SEP_NEGATE_RE = /[^\\/]+/g;
    
  • This change will allow the function to split paths with either separator.

Example:

For the input path C:\\Users\\Administrator\\Documents\\KKNote\\Notes.md, the expected output should be:

[
  "C:",
  "Users",
  "Administrator",
  "Documents",
  "KKNote",
  "Notes.md"
]

winner106 avatar Feb 25 '25 15:02 winner106

Would accept a PR for this!

jaredLunde avatar Feb 25 '25 17:02 jaredLunde