Skip to content

Conversation

@biplobmanna
Copy link

Parse windows style and *nix style host filepath properly

Examples, of what's accepted:

  • windows filepath
    • eg: C:\some\thing
    • eg: C:/some/thing
  • *nix style filepath
    • eg: /mnt/C/some/thing
    • eg: /host_mnt/C/some/thing
    • eg: /run/desktop/mnt/host/C/some/thing

Logic:

  • First check if valid Windows Filepath
  • Next, parse *nix style filepath
    • convert to windows filepath

Created a PR based on my comment in another PR for this

- windows filepath
  - eg: C:\some\thing
  - eg: C:/some/thing
- *nix style filepath
  - eg: /mnt/C/some/thing
  - eg: /host_mnt/C/some/thing
  - eg: /run/desktop/mnt/host/C/some/thing

First check if valid Windows Filepath
Next, parse *nix style filepath
convert to windows filepath
@biplobmanna
Copy link
Author

Logic of the regex:

  1. ^[a-zA-Z]\:(/|\\\\).*$
  • Check the first char is a valid drive letter
  • Check the second is : (colon)
  • Check the third char is / (slash) or \ (backslash)
  • The rest doesn't matter (as it's presumed a valid path is always passed)
  1. ^(?:.*)?/([a-zA-Z])/(.*)$
  • ?: says that it's a non-capturing group
  • don't capture anything until we find / (slash) followed by a valid drive-letter
  • the next should be / (slash)
  • the rest don't matter (as it's presumed a valid path is always passed)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant