Skip to content

Commit

Permalink
feat: make generic.is_url() accept dollar-quoted userinfo fragments
Browse files Browse the repository at this point in the history
Part of supporting authenticated remote styles requires a way to specify
authinfo without necessarily hardcoding a sensitive token in the config
file.

This is done by interpolating an environment variable if the url
username fragment begins with a `$`, but that fails the original
`nitpick.generic.URL_RE` pattern, because `\w` weirdly doesn't match
`$`.
  • Loading branch information
tfh-cri authored and andreoliwa committed Nov 7, 2021
1 parent c922dcd commit ef99acd
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/nitpick/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from nitpick.constants import DOUBLE_QUOTE, PROJECT_NAME, SEPARATOR_FLATTEN, SEPARATOR_QUOTED_SPLIT, SINGLE_QUOTE
from nitpick.typedefs import JsonDict, PathOrStr

URL_RE = re.compile(r"[a-z]+://\w+")
URL_RE = re.compile(r"[a-z]+://[\$\w]\w*")


def get_subclasses(cls):
Expand Down Expand Up @@ -222,6 +222,12 @@ def is_url(url: str) -> bool:
True
>>> is_url("github://andreoliwa/nitpick/styles/black")
True
>>> is_url("github://$VARNAME@andreoliwa/nitpick/styles/black")
True
>>> is_url("github://LitErAl@andreoliwa/nitpick/styles/black")
True
>>> is_url("github://notfirst$@andreoliwa/nitpick/styles/black")
True
"""
return bool(URL_RE.match(url))

Expand Down

0 comments on commit ef99acd

Please sign in to comment.