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
069e884f
Commit
069e884f
authored
Apr 16, 2016
by
Robert Raposa
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #12129 from edx/robrap/linter-mako
TNL-4324: Add check for HTML entities
parents
a406a221
14abf32b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
3 deletions
+25
-3
scripts/safe_template_linter.py
+17
-3
scripts/tests/test_safe_template_linter.py
+8
-0
No files found.
scripts/safe_template_linter.py
View file @
069e884f
...
...
@@ -246,6 +246,10 @@ class Rules(Enum):
'mako-wrap-html'
,
"String containing HTML should be wrapped with call to HTML()."
)
mako_html_entities
=
(
'mako-html-entities'
,
"HTML entities should be plain text or wrapped with HTML()."
)
underscore_not_escaped
=
(
'underscore-not-escaped'
,
'Expressions should be escaped using <
%-
expression
%
>.'
...
...
@@ -761,7 +765,7 @@ class MakoTemplateLinter(object):
context
=
self
.
_get_context
(
contexts
,
expression
[
'start_index'
])
self
.
_check_filters
(
mako_template
,
expression
,
context
,
has_page_default
,
results
)
self
.
_check_deprecated_display_name
(
expression
,
results
)
self
.
_check_html_and_text
(
expression
,
results
)
self
.
_check_html_and_text
(
expression
,
has_page_default
,
results
)
def
_check_deprecated_display_name
(
self
,
expression
,
results
):
"""
...
...
@@ -779,13 +783,15 @@ class MakoTemplateLinter(object):
Rules
.
mako_deprecated_display_name
,
expression
))
def
_check_html_and_text
(
self
,
expression
,
results
):
def
_check_html_and_text
(
self
,
expression
,
has_page_default
,
results
):
"""
Checks rules related to proper use of HTML() and Text().
Arguments:
expression: A dict containing the start_index, end_index, and
expression (text) of the expression.
has_page_default: True if the page is marked as default, False
otherwise.
results: A list of results into which violations will be added.
"""
...
...
@@ -836,13 +842,21 @@ class MakoTemplateLinter(object):
if
html_inner_start_index
<=
string
.
start_index
and
string
.
end_index
<=
html_inner_end_index
:
unwrapped_html_strings
.
remove
(
string
)
# check strings not wrapped in HTML()
# check strings not wrapped in HTML()
for '<'
for
string
in
unwrapped_html_strings
:
if
'<'
in
string
.
string_inner
:
results
.
violations
.
append
(
ExpressionRuleViolation
(
Rules
.
mako_wrap_html
,
expression
))
break
# check strings not wrapped in HTML() for HTML entities
if
has_page_default
:
for
string
in
unwrapped_html_strings
:
if
re
.
search
(
r"&[#]?[a-zA-Z0-9]+;"
,
string
.
string_inner
):
results
.
violations
.
append
(
ExpressionRuleViolation
(
Rules
.
mako_html_entities
,
expression
))
break
def
_check_filters
(
self
,
mako_template
,
expression
,
context
,
has_page_default
,
results
):
"""
...
...
scripts/tests/test_safe_template_linter.py
View file @
069e884f
...
...
@@ -255,6 +255,14 @@ class TestMakoTemplateLinter(TestCase):
'expression'
:
"${ HTML('<span></span>') + 'some other text' }"
,
'rule'
:
Rules
.
mako_html_alone
},
{
'expression'
:
"${'Rock & Roll'}"
,
'rule'
:
Rules
.
mako_html_entities
},
{
'expression'
:
"${'Rock & Roll'}"
,
'rule'
:
Rules
.
mako_html_entities
},
)
def
test_check_mako_with_text_and_html
(
self
,
data
):
"""
...
...
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