Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pystache_custom
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
OpenEdx
pystache_custom
Commits
4e9f0064
Commit
4e9f0064
authored
Dec 25, 2011
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed issue #67: "Use cgi.escape() with quote=True"
parent
0aabea24
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
7 deletions
+16
-7
pystache/renderer.py
+10
-5
tests/test_renderer.py
+6
-2
No files found.
pystache/renderer.py
View file @
4e9f0064
...
...
@@ -92,8 +92,13 @@ class Renderer(object):
default_encoding
=
sys
.
getdefaultencoding
()
if
escape
is
None
:
# TODO: use 'quote=True' with cgi.escape and add tests.
escape
=
markupsafe
.
escape
if
markupsafe
else
cgi
.
escape
if
markupsafe
:
escape
=
markupsafe
.
escape
else
:
# The quote=True argument causes double quotes to be escaped,
# but not single quotes:
# http://docs.python.org/library/cgi.html#cgi.escape
escape
=
lambda
s
:
cgi
.
escape
(
s
,
quote
=
True
)
if
loader
is
None
:
loader
=
Loader
(
encoding
=
default_encoding
,
decode_errors
=
decode_errors
)
...
...
@@ -108,7 +113,7 @@ class Renderer(object):
def
_to_unicode_soft
(
self
,
s
):
"""
Convert a
n str or unicode string to a unicode string (or subclass)
.
Convert a
basestring to unicode, preserving any unicode subclass
.
"""
# Avoid the "double-decoding" TypeError.
...
...
@@ -116,14 +121,14 @@ class Renderer(object):
def
_to_unicode_hard
(
self
,
s
):
"""
Convert a
n str or unicode string to a unicode string
(not subclass).
Convert a
basestring to a string with type unicode
(not subclass).
"""
return
unicode
(
self
.
_to_unicode_soft
(
s
))
def
_escape_to_unicode
(
self
,
s
):
"""
Convert a
n str or unicode string to unicode
, and escape it.
Convert a
basestring to unicode (preserving any unicode subclass)
, and escape it.
Returns a unicode string (not subclass).
...
...
tests/test_renderer.py
View file @
4e9f0064
...
...
@@ -97,8 +97,12 @@ class RendererTestCase(unittest.TestCase):
self
.
assertEquals
(
bool
(
markupsafe
),
self
.
_was_markupsafe_imported
())
def
test_init__escape__default_without_markupsafe
(
self
):
renderer
=
Renderer
()
self
.
assertEquals
(
renderer
.
escape
(
">'"
),
">'"
)
escape
=
Renderer
()
.
escape
self
.
assertEquals
(
escape
(
">"
),
">"
)
self
.
assertEquals
(
escape
(
'"'
),
"""
)
# Single quotes are not escaped.
self
.
assertEquals
(
escape
(
"'"
),
"'"
)
def
test_init__escape__default_with_markupsafe
(
self
):
if
not
self
.
_was_markupsafe_imported
():
...
...
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