Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor 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
Hsin-Yu Chien
edx-platform-release
Commits
8a30a54d
Commit
8a30a54d
authored
8 years ago
by
Robert Raposa
Browse files
Options
Downloads
Plain Diff
Merge pull request #12536 from edx/robrap/linter-concat-html
Fix false positives on javascript_contact_html.
parents
641f29b6
ff862612
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
scripts/safe_template_linter.py
+25
-4
25 additions, 4 deletions
scripts/safe_template_linter.py
scripts/tests/test_safe_template_linter.py
+10
-0
10 additions, 0 deletions
scripts/tests/test_safe_template_linter.py
with
35 additions
and
4 deletions
scripts/safe_template_linter.py
+
25
−
4
View file @
8a30a54d
...
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
scripts/tests/test_safe_template_linter.py
+
10
−
0
View file @
8a30a54d
...
...
@@ -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
},
...
...
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