Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
klaus
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
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
GitHub Mirror
jonashaag
klaus
Commits
d48655f4
Commit
d48655f4
authored
7 years ago
by
Jonas Haag
Browse files
Options
Downloads
Patches
Plain Diff
Fix security issue #200
parent
bd7dfe65
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
klaus/diff.py
+8
-6
8 additions, 6 deletions
klaus/diff.py
klaus/utils.py
+5
-0
5 additions, 0 deletions
klaus/utils.py
with
13 additions
and
6 deletions
klaus/diff.py
+
8
−
6
View file @
d48655f4
...
...
@@ -10,6 +10,8 @@
"""
from
difflib
import
SequenceMatcher
from
klaus.utils
import
escape_html
as
e
def
highlight_line
(
old_line
,
new_line
):
"""
Highlight inline changes in both lines.
"""
...
...
@@ -55,23 +57,23 @@ def render_diff(a, b, n=3):
for
tag
,
i1
,
i2
,
j1
,
j2
in
group
:
if
tag
==
'
equal
'
:
for
c
,
line
in
enumerate
(
a
[
i1
:
i2
]):
add_line
(
i1
+
c
,
j1
+
c
,
'
unmod
'
,
line
)
add_line
(
i1
+
c
,
j1
+
c
,
'
unmod
'
,
e
(
line
)
)
elif
tag
==
'
insert
'
:
for
c
,
line
in
enumerate
(
b
[
j1
:
j2
]):
add_line
(
None
,
j1
+
c
,
'
add
'
,
line
)
add_line
(
None
,
j1
+
c
,
'
add
'
,
e
(
line
)
)
elif
tag
==
'
delete
'
:
for
c
,
line
in
enumerate
(
a
[
i1
:
i2
]):
add_line
(
i1
+
c
,
None
,
'
del
'
,
line
)
add_line
(
i1
+
c
,
None
,
'
del
'
,
e
(
line
)
)
elif
tag
==
'
replace
'
:
# TODO: not sure if this is the best way to deal with replace
# blocks, but it's consistent with the previous version.
for
c
,
line
in
enumerate
(
a
[
i1
:
i2
-
1
]):
add_line
(
i1
+
c
,
None
,
'
del
'
,
line
)
old_line
,
new_line
=
highlight_line
(
a
[
i2
-
1
],
b
[
j1
])
add_line
(
i1
+
c
,
None
,
'
del
'
,
e
(
line
)
)
old_line
,
new_line
=
highlight_line
(
e
(
a
[
i2
-
1
]
)
,
e
(
b
[
j1
])
)
add_line
(
i2
-
1
,
None
,
'
del
'
,
old_line
)
add_line
(
None
,
j1
,
'
add
'
,
new_line
)
for
c
,
line
in
enumerate
(
b
[
j1
+
1
:
j2
]):
add_line
(
None
,
j1
+
c
+
1
,
'
add
'
,
line
)
add_line
(
None
,
j1
+
c
+
1
,
'
add
'
,
e
(
line
)
)
else
:
raise
AssertionError
(
'
unknown tag %s
'
%
tag
)
...
...
This diff is collapsed.
Click to expand it.
klaus/utils.py
+
5
−
0
View file @
d48655f4
...
...
@@ -236,3 +236,8 @@ def sanitize_branch_name(name, chars='./', repl='-'):
for
char
in
chars
:
name
=
name
.
replace
(
char
,
repl
)
return
name
def
escape_html
(
s
):
return
s
.
replace
(
b
'
&
'
,
b
'
&
'
).
replace
(
b
'
<
'
,
b
'
<
'
)
\
.
replace
(
b
'
>
'
,
b
'
>
'
).
replace
(
b
'"'
,
b
'
"
'
)
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