Skip to content

Commit

Permalink
Merge pull request #231 from e-sonic/SNC-20326-passwd-enc-fix
Browse files Browse the repository at this point in the history
Fixed copy command URL invalid - password encoding
  • Loading branch information
bhavini-gada authored and GitHub Enterprise committed Nov 10, 2022
2 parents 5ba2b52 + a2afb42 commit 62546e6
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions CLI/actioner/sonic_cli_file_mgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from pprint import pprint
import json
import getpass
import urllib.parse as urlparse

# URL Pattern
# Protocol://[Username[:Password]@]Hostname[:Port]/[Filename]
Expand All @@ -38,7 +39,7 @@
# Port - 0-9 (0-99999) - optional
# Filename - can contain any caharacter other than {:?&@} as these characters have special meaning in URL

url_pattern = r"^(http:\/\/|scp:\/\/|ftp:\/\/)(([a-zA-Z0-9.]+@)?|([a-zA-Z0-9.]+:[^:?&@]+)@)?([.a-zA-Z0-9\-]+(:[0-9]{1,5})?/[^:?&@]+)$"
url_pattern = r"^(http:\/\/|scp:\/\/|ftp:\/\/)(([a-zA-Z0-9.]+@)?|([a-zA-Z0-9.]+:[^:?&@]+)@)?([.a-zA-Z0-9\-]+(:[0-9]{1,5})?(:)?/[^:?&@]+)$"

def is_remote_url(url):
remote_url_prefixes = ["http:", "ftp:", "scp:"]
Expand Down Expand Up @@ -96,7 +97,8 @@ def get_user_pass(url):
if (status == False) or (len(password) == 0):
return False, ""

url = f"{url_prefix}{username}:{password}@{host_filename}"
password_enc = urlparse.quote(password)
url = f"{url_prefix}{username}:{password_enc}@{host_filename}"

if (len(url) <= 256) and is_valid_url(url):
return (True, url)
Expand Down

0 comments on commit 62546e6

Please sign in to comment.