merofeev / docker-windows-volume-watcher

A tool to notify Docker contianers about changes in mounts on Windows.
MIT License
188 stars 30 forks source link

fix: parsing multiple filepath formats #24

Open biplobmanna opened 1 year ago

biplobmanna commented 1 year ago

Parse windows style and *nix style host filepath properly

Examples, of what's accepted:

Logic:

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

biplobmanna commented 1 year ago

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)
  2. ^(?:.*)?/([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)