Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
ff862612
Commit
ff862612
authored
May 20, 2016
by
Robert Raposa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix false positives on javascript_contact_html.
parent
76685e4e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
4 deletions
+35
-4
scripts/safe_template_linter.py
+25
-4
scripts/tests/test_safe_template_linter.py
+10
-0
No files found.
scripts/safe_template_linter.py
View file @
ff862612
...
...
@@ -1365,10 +1365,31 @@ class JavaScriptLinter(BaseLinter):
"""
lines
=
StringLines
(
file_contents
)
last_expression
=
None
# attempt to match a string that starts with '<' or ends with '>'
regex_string_with_html
=
r"""["'](?:\s*<.*|.*>\s*)["']"""
regex_concat_with_html
=
r"(\+\s*{}|{}\s*\+)"
.
format
(
regex_string_with_html
,
regex_string_with_html
)
for
match
in
re
.
finditer
(
regex_concat_with_html
,
file_contents
):
# Match quoted strings that starts with '<' or ends with '>'.
regex_string_with_html
=
r"""
{quote} # Opening quote.
(
\s*< # Starts with '<' (ignoring spaces)
([^{quote}]|[\\]{quote})* # followed by anything but a closing quote.
| # Or,
([^{quote}]|[\\]{quote})* # Anything but a closing quote
>\s* # ending with '>' (ignoring spaces)
)
{quote} # Closing quote.
"""
# Match single or double quote.
regex_string_with_html
=
"({}|{})"
.
format
(
regex_string_with_html
.
format
(
quote
=
"'"
),
regex_string_with_html
.
format
(
quote
=
'"'
),
)
# Match quoted HTML strings next to a '+'.
regex_concat_with_html
=
re
.
compile
(
r"(\+\s*{string_with_html}|{string_with_html}\s*\+)"
.
format
(
string_with_html
=
regex_string_with_html
,
),
re
.
VERBOSE
)
for
match
in
regex_concat_with_html
.
finditer
(
file_contents
):
found_new_violation
=
False
if
last_expression
is
not
None
:
last_line
=
lines
.
index_to_line_number
(
last_expression
.
start_index
)
...
...
scripts/tests/test_safe_template_linter.py
View file @
ff862612
...
...
@@ -1079,7 +1079,17 @@ class TestJavaScriptLinter(TestLinter):
@data
(
{
'template'
:
'var m = "Plain text " + message + "plain text"'
,
'rule'
:
None
},
{
'template'
:
'var m = "檌檒濦 " + message + "plain text"'
,
'rule'
:
None
},
{
'template'
:
(
"""$email_header.append($('<input>', type: "button", name: "copy-email-body-text","""
""" value: gettext("Copy Email To Editor"), id: 'copy_email_' + email_id))"""
),
'rule'
:
None
},
{
'template'
:
'var m = "<p>" + message + "</p>"'
,
'rule'
:
Rules
.
javascript_concat_html
},
{
'template'
:
r'var m = "<p>\"escaped quote\"" + message + "\"escaped quote\"</p>"'
,
'rule'
:
Rules
.
javascript_concat_html
},
{
'template'
:
' // var m = "<p>" + commentedOutMessage + "</p>"'
,
'rule'
:
None
},
{
'template'
:
'var m = " <p> " + message + " </p> "'
,
'rule'
:
Rules
.
javascript_concat_html
},
{
'template'
:
'var m = " <p> " + message + " broken string'
,
'rule'
:
Rules
.
javascript_concat_html
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment