Skip to content

Commit f484a33

Browse files
committed
Sjoerd writes:
When literal mode is entered it should exit automatically when the matching close tag of the last unclosed open tag is encountered. This patch fixes this.
1 parent 926f7b6 commit f484a33

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

Doc/lib/libxmllib.tex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ \section{\module{xmllib} ---
2727
\end{methoddesc}
2828

2929
\begin{methoddesc}{setliteral}{}
30-
Enter literal mode (CDATA mode).
30+
Enter literal mode (CDATA mode). This mode is automatically exited
31+
when the close tag matching the last unclosed open tag is encountered.
3132
\end{methoddesc}
3233

3334
\begin{methoddesc}{feed}{data}

Lib/xmllib.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ def goahead(self, end):
205205
if k < 0: break
206206
self.lineno = self.lineno + string.count(rawdata[i:k], '\n')
207207
i = k
208-
self.literal = 0
209208
continue
210209
if commentopen.match(rawdata, i):
211210
if self.literal:
@@ -503,11 +502,19 @@ def parse_endtag(self, i):
503502
return -1
504503
res = tagfind.match(rawdata, i+2)
505504
if res is None:
505+
if self.literal:
506+
self.handle_data(rawdata[i])
507+
return i+1
506508
self.syntax_error('no name specified in end tag')
507509
tag = ''
508510
k = i+2
509511
else:
510512
tag = res.group(0)
513+
if self.literal:
514+
if not self.stack or tag != self.stack[-1]:
515+
self.handle_data(rawdata[i])
516+
return i+1
517+
self.literal = 0
511518
k = res.end(0)
512519
if endbracket.match(rawdata, k) is None:
513520
self.syntax_error('garbage in end tag')

0 commit comments

Comments
 (0)