Skip to content
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

{upload|delete}_file: Remove client-side filename validation #669

Merged
merged 4 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions src/huggingface_hub/hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# limitations under the License.
import logging
import os
import re
import subprocess
import sys
import warnings
Expand Down Expand Up @@ -49,10 +48,6 @@

USERNAME_PLACEHOLDER = "hf_user"

REMOTE_FILEPATH_REGEX = re.compile(r"^\w[\w\/\-]*(\.\w+)?$")
# ^^ No trailing slash, no backslash, no spaces, no relative parts ("." or "..")
# Only word characters and an optional extension


def repo_type_and_id_from_hf_id(hf_id: str):
"""
Expand Down Expand Up @@ -1354,14 +1349,6 @@ def upload_file(
"If you passed a fileobj, make sure you've opened the file in binary mode."
)

# Normalize path separators and strip leading slashes
if not REMOTE_FILEPATH_REGEX.match(path_in_repo):
raise ValueError(
"Invalid path_in_repo '{}', path_in_repo must match regex {}".format(
path_in_repo, REMOTE_FILEPATH_REGEX.pattern
)
)

if repo_type in REPO_TYPES_URL_PREFIXES:
repo_id = REPO_TYPES_URL_PREFIXES[repo_type] + repo_id

Expand Down Expand Up @@ -1436,14 +1423,6 @@ def delete_file(
"`huggingface-cli login`."
)

# Normalize path separators and strip leading slashes
if not REMOTE_FILEPATH_REGEX.match(path_in_repo):
raise ValueError(
"Invalid path_in_repo '{}', path_in_repo must match regex {}".format(
path_in_repo, REMOTE_FILEPATH_REGEX.pattern
)
)

if repo_type in REPO_TYPES_URL_PREFIXES:
repo_id = REPO_TYPES_URL_PREFIXES[repo_type] + repo_id

Expand Down
1 change: 0 additions & 1 deletion tests/test_hubmixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def __init__(self, **kwargs):
def forward(self, x):
return self.l1(x)


else:
DummyModel = None

Expand Down
1 change: 0 additions & 1 deletion tests/test_keras_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def __init__(self, **kwargs):
def call(self, x):
return self.l1(x)


else:
DummyModel = None

Expand Down