Skip to content

fix: parsing multiple filepath formats #24

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 1 commit into
base: master
Choose a base branch
from

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