Skip to content

Commit

Permalink
Updated code to handle test cases and comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Krishn1412 committed Dec 13, 2024
1 parent fe1a82a commit 626da2d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions falcon/util/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
import functools
import http
import inspect
import os
import re
from typing import Any, Callable, Dict, List, Mapping, Optional, Tuple, Union
import unicodedata
import os

from falcon import status_codes
from falcon.constants import PYPY
Expand Down Expand Up @@ -337,7 +337,7 @@ def get_argnames(func: Callable[..., Any]) -> List[str]:
return args


def secure_filename(filename: str, max_length: int = None) -> str:
def secure_filename(filename: str, max_length: Optional[int] = None) -> str:
"""Sanitize the provided `filename` to contain only ASCII characters.
Only ASCII alphanumerals, ``'.'``, ``'-'`` and ``'_'`` are allowed for
Expand Down Expand Up @@ -380,7 +380,10 @@ def secure_filename(filename: str, max_length: int = None) -> str:

if max_length is not None and len(filename) > max_length:
name, ext = os.path.splitext(filename)

Check warning on line 382 in falcon/util/misc.py

View check run for this annotation

Codecov / codecov/patch

falcon/util/misc.py#L382

Added line #L382 was not covered by tests
filename = name[:max_length - len(ext)] + ext
if max_length < len(ext):
filename = ext[:max_length]

Check warning on line 384 in falcon/util/misc.py

View check run for this annotation

Codecov / codecov/patch

falcon/util/misc.py#L384

Added line #L384 was not covered by tests
else:
filename = name[: max_length - len(ext)] + ext

Check warning on line 386 in falcon/util/misc.py

View check run for this annotation

Codecov / codecov/patch

falcon/util/misc.py#L386

Added line #L386 was not covered by tests

return filename

Expand Down

0 comments on commit 626da2d

Please sign in to comment.