Skip to content

Commit fd42132

Browse files
committed
Web: Fix <title> extraction in presence of nested <svg>
1 parent 8ec8730 commit fd42132

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

plugins/Web/plugin.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
###
22
# Copyright (c) 2005, Jeremiah Fincher
33
# Copyright (c) 2009, James McCoy
4-
# Copyright (c) 2010-2021, Valentin Lorentz
4+
# Copyright (c) 2010-2024, Valentin Lorentz
55
# All rights reserved.
66
#
77
# Redistribution and use in source and binary forms, with or without
@@ -59,24 +59,24 @@ class Title(utils.web.HtmlToText):
5959
entitydefs['nbsp'] = ' '
6060
def __init__(self):
6161
self.inTitle = False
62-
self.inSvg = False
62+
self.inSvg = 0 # counter instead of boolean because svg can be nested
6363
utils.web.HtmlToText.__init__(self)
6464

6565
@property
6666
def inHtmlTitle(self):
67-
return self.inTitle and not self.inSvg
67+
return self.inTitle and self.inSvg == 0
6868

6969
def handle_starttag(self, tag, attrs):
7070
if tag == 'title':
7171
self.inTitle = True
7272
elif tag == 'svg':
73-
self.inSvg = True
73+
self.inSvg += 1
7474

7575
def handle_endtag(self, tag):
7676
if tag == 'title':
7777
self.inTitle = False
7878
elif tag == 'svg':
79-
self.inSvg = False
79+
self.inSvg = max(0, self.inSvg - 1)
8080

8181
def append(self, data):
8282
if self.inHtmlTitle:

0 commit comments

Comments
 (0)