Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
4dc97b90
Commit
4dc97b90
authored
Dec 16, 2002
by
Evan Simpson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Collector #721 by preserving syntactically valid character entities in attributes.
parent
2857f5d3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
12 deletions
+34
-12
lib/python/TAL/TALDefs.py
lib/python/TAL/TALDefs.py
+21
-0
lib/python/TAL/TALGenerator.py
lib/python/TAL/TALGenerator.py
+1
-1
lib/python/TAL/tests/test_talinterpreter.py
lib/python/TAL/tests/test_talinterpreter.py
+12
-11
No files found.
lib/python/TAL/TALDefs.py
View file @
4dc97b90
...
@@ -164,3 +164,24 @@ def getProgramVersion(program):
...
@@ -164,3 +164,24 @@ def getProgramVersion(program):
if opcode == "
version
":
if opcode == "
version
":
return version
return version
return None
return None
import re
_ent1_re = re.compile('&(?![A-Z#])', re.I)
_entch_re = re.compile('&([A-Z][A-Z0-9]*)(?![A-Z0-9;])', re.I)
_entn1_re = re.compile('&#(?![0-9X])', re.I)
_entnx_re = re.compile('&(#X[A-F0-9]*)(?![A-F0-9;])', re.I)
_entnd_re = re.compile('&(#[0-9][0-9]*)(?![0-9;])')
del re
def attrEscape(s):
"""Replace special characters '&<>' by character entities,
except when '&' already begins a syntactically valid entity."""
s = _ent1_re.sub('&', s)
s = _entch_re.sub(r'&
\
1
', s)
s = _entn1_re.sub('&#', s)
s = _entnx_re.sub(r'&
\
1
', s)
s = _entnd_re.sub(r'&
\
1
', s)
s = s.replace('<', '<')
s = s.replace('>', '>')
s = s.replace('"', '
&
quot
;
')
return s
lib/python/TAL/TALGenerator.py
View file @
4dc97b90
...
@@ -162,7 +162,7 @@ class TALGenerator:
...
@@ -162,7 +162,7 @@ class TALGenerator:
if
item
[
1
]
is
None
:
if
item
[
1
]
is
None
:
s
=
item
[
0
]
s
=
item
[
0
]
else
:
else
:
s
=
'%s="%s"'
%
(
item
[
0
],
cgi
.
escape
(
item
[
1
],
1
))
s
=
'%s="%s"'
%
(
item
[
0
],
TALDefs
.
attrEscape
(
item
[
1
]
))
attrlist
[
i
]
=
item
[
0
],
s
attrlist
[
i
]
=
item
[
0
],
s
new
.
append
(
" "
+
s
)
new
.
append
(
" "
+
s
)
# if no non-optimizable attributes were found, convert to plain text
# if no non-optimizable attributes were found, convert to plain text
...
...
lib/python/TAL/tests/test_talinterpreter.py
View file @
4dc97b90
...
@@ -62,31 +62,32 @@ class OutputPresentationTestCase(TestCaseBase):
...
@@ -62,31 +62,32 @@ class OutputPresentationTestCase(TestCaseBase):
attributes=", so" the="output" needs="to"
attributes=", so" the="output" needs="to"
be="line" wrapped=".">
be="line" wrapped=".">
</html>'''
"
\
n
"
</html>'''
"
\
n
"
program
,
macros
=
self
.
_compile
(
INPUT
)
self
.
compare
(
INPUT
,
EXPECTED
)
sio
=
StringIO
()
interp
=
TALInterpreter
(
program
,
{},
DummyEngine
(),
sio
,
wrap
=
60
)
interp
()
self
.
assertEqual
(
sio
.
getvalue
(),
EXPECTED
)
def
check_unicode_content
(
self
):
def
check_unicode_content
(
self
):
INPUT
=
"""<p tal:content="python:u'dj-vu'">para</p>"""
INPUT
=
"""<p tal:content="python:u'dj-vu'">para</p>"""
EXPECTED
=
u"""<p>dj-vu</p>"""
"
\
n
"
EXPECTED
=
u"""<p>dj-vu</p>"""
"
\
n
"
program
,
macros
=
self
.
_compile
(
INPUT
)
self
.
compare
(
INPUT
,
EXPECTED
)
sio
=
StringIO
()
interp
=
TALInterpreter
(
program
,
{},
DummyEngine
(),
sio
,
wrap
=
60
)
interp
()
self
.
assertEqual
(
sio
.
getvalue
(),
EXPECTED
)
def
check_unicode_structure
(
self
):
def
check_unicode_structure
(
self
):
INPUT
=
"""<p tal:replace="structure python:u'dj-vu'">para</p>"""
INPUT
=
"""<p tal:replace="structure python:u'dj-vu'">para</p>"""
EXPECTED
=
u"""dj-vu"""
"
\
n
"
EXPECTED
=
u"""dj-vu"""
"
\
n
"
self
.
compare
(
INPUT
,
EXPECTED
)
def
check_entities
(
self
):
INPUT
=
(
'<img tal:define="foo nothing" '
'alt="&a;  
 &a - &; �a; <>" />'
)
EXPECTED
=
(
'<img alt="&a;  
 '
'&a &#45 &; &#0a; <>" />
\
n
'
)
self
.
compare
(
INPUT
,
EXPECTED
)
def
compare
(
self
,
INPUT
,
EXPECTED
):
program
,
macros
=
self
.
_compile
(
INPUT
)
program
,
macros
=
self
.
_compile
(
INPUT
)
sio
=
StringIO
()
sio
=
StringIO
()
interp
=
TALInterpreter
(
program
,
{},
DummyEngine
(),
sio
,
wrap
=
60
)
interp
=
TALInterpreter
(
program
,
{},
DummyEngine
(),
sio
,
wrap
=
60
)
interp
()
interp
()
self
.
assertEqual
(
sio
.
getvalue
(),
EXPECTED
)
self
.
assertEqual
(
sio
.
getvalue
(),
EXPECTED
)
def
test_suite
():
def
test_suite
():
suite
=
unittest
.
TestSuite
()
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
MacroErrorsTestCase
,
"check_"
))
suite
.
addTest
(
unittest
.
makeSuite
(
MacroErrorsTestCase
,
"check_"
))
...
...
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