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

Substitute illegal characters in filename to hyphen #479

Merged
merged 9 commits into from
Jun 29, 2023
8 changes: 4 additions & 4 deletions src/app/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def license_compare_helper(request):
base_url=urljoin(settings.MEDIA_URL, folder+'/')
)
for myfile in request.FILES.getlist("files"):
filename = fs.save(myfile.name, myfile)
filename = fs.save(utils.removeSpecialCharacters(myfile.name), myfile)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6% of developers fix this issue

E501: line too long (86 > 79 characters)

❗❗ 3 similar findings have been found in this PR

🔎 Expand here to view all instances of this finding
File Path Line Number
src/app/core.py 209
src/app/core.py 319
src/app/core.py 491

Visit the Lift Web Console to find more details in your report.


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.

uploaded_file_url = fs.url(filename).replace("%20", " ")
callfunc.append(settings.APP_DIR+uploaded_file_url)
nameoffile, fileext = os.path.splitext(filename)
Expand Down Expand Up @@ -206,7 +206,7 @@ def ntia_check_helper(request):
fs = FileSystemStorage(location=settings.MEDIA_ROOT + "/" + folder,
base_url=urljoin(settings.MEDIA_URL, folder + '/')
)
filename = fs.save(myfile.name, myfile)
filename = fs.save(utils.removeSpecialCharacters(myfile.name), myfile)
uploaded_file_url = fs.url(filename).replace("%20", " ")
""" Call the python SBOM Checker """
schecker = SbomChecker(str(settings.APP_DIR + uploaded_file_url))
Expand Down Expand Up @@ -316,7 +316,7 @@ def license_validate_helper(request):
fs = FileSystemStorage(location=settings.MEDIA_ROOT +"/"+ folder,
base_url=urljoin(settings.MEDIA_URL, folder+'/')
)
filename = fs.save(myfile.name, myfile)
filename = fs.save(utils.removeSpecialCharacters(myfile.name), myfile)
uploaded_file_url = fs.url(filename).replace("%20", " ")
formatstr = request.POST["format"]
serFileTypeEnum = jpype.JClass("org.spdx.tools.SpdxToolsHelper$SerFileType")
Expand Down Expand Up @@ -488,7 +488,7 @@ def license_convert_helper(request):
folder = str(request.user) + "/" + str(int(time()))
myfile = request.FILES['file']
fs = FileSystemStorage(location=settings.MEDIA_ROOT +"/"+ folder,base_url=urljoin(settings.MEDIA_URL, folder+'/'))
filename = fs.save(myfile.name, myfile)
filename = fs.save(utils.removeSpecialCharacters(myfile.name), myfile)
uploaded_file_url = fs.url(filename).replace("%20", " ")
option1 = request.POST["from_format"]
option2 = request.POST["to_format"]
Expand Down
5 changes: 5 additions & 0 deletions src/app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import logging
import re
import socket
import unicodedata
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

9% of developers fix this issue

F401: 'unicodedata' imported but unused


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

20% of developers fix this issue

vulture-90: unused import 'unicodedata'


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.

import xml.etree.cElementTree as ET

import redis
Expand Down Expand Up @@ -367,6 +368,10 @@ def postToGithub(message, encodedContent, filename):
return r.status_code, r.json()


def removeSpecialCharacters(filename):
return re.sub(r'[#%&{}<>*?/$!\'":@+`|=]', "-", filename)


def parseXmlString(xmlString):
""" View for generating a spdx license xml
returns a dictionary with the xmlString license fields values
Expand Down