Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
diffoscope
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Reproducible Builds
diffoscope
Commits
a36ee4eb
Commit
a36ee4eb
authored
4 months ago
by
Chris Lamb
Browse files
Options
Downloads
Patches
Plain Diff
Validate --css argument. Thanks to Daniel Schmidt @ SRLabs for the report. (Closes:
#396
)
parent
0682af7c
No related branches found
No related tags found
No related merge requests found
Pipeline
#796994
failed
4 months ago
Stage: test
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
diffoscope/main.py
+13
-0
13 additions, 0 deletions
diffoscope/main.py
tests/test_main.py
+28
-0
28 additions, 0 deletions
tests/test_main.py
with
41 additions
and
0 deletions
diffoscope/main.py
+
13
−
0
View file @
a36ee4eb
...
...
@@ -28,6 +28,8 @@ import textwrap
import
argparse
import
traceback
from
urllib.parse
import
urlparse
from
.
import
VERSION
from
.path
import
set_path
from
.tools
import
(
...
...
@@ -734,6 +736,14 @@ def sigterm_handler(signo, stack_frame):
os
.
_exit
(
2
)
def
is_valid_url
(
val
):
try
:
result
=
urlparse
(
val
)
return
all
([
result
.
scheme
,
result
.
netloc
])
except
AttributeError
:
return
False
def
main
(
args
=
None
):
if
args
is
None
:
args
=
sys
.
argv
[
1
:]
...
...
@@ -759,6 +769,9 @@ def main(args=None):
parser
,
post_parse
=
create_parser
()
parsed_args
=
parser
.
parse_args
(
args
)
if
parsed_args
.
css_url
and
not
is_valid_url
(
parsed_args
.
css_url
):
parser
.
error
(
f
"
{
parsed_args
.
css_url
!r}
is not a valid CSS URL.
"
)
log_handler
=
ProgressManager
().
setup
(
parsed_args
)
with
setup_logging
(
parsed_args
.
debug
,
log_handler
)
as
_
:
...
...
This diff is collapsed.
Click to expand it.
tests/test_main.py
+
28
−
0
View file @
a36ee4eb
...
...
@@ -191,3 +191,31 @@ def test_usage(capsys):
assert
out
==
""
assert
"
usage:
"
in
err
def
test_valid_css
(
capsys
):
ret
,
out
,
err
=
run
(
capsys
,
"
--css
"
,
"
http://example.tld/file.css
"
,
TEST_TAR1_PATH
,
TEST_TAR1_PATH
,
)
assert
ret
==
0
assert
err
==
""
assert
out
==
""
def
test_invalid_css
(
capsys
):
ret
,
out
,
err
=
run
(
capsys
,
"
--css
"
,
'"
><svg/onload=alert(43433)>
'
,
TEST_TAR1_PATH
,
TEST_TAR1_PATH
,
)
assert
ret
==
2
assert
"
is not a valid CSS
"
in
err
assert
out
==
""
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment