Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
29877e8e
Kaydet (Commit)
29877e8e
authored
Şub 21, 2012
tarafından
Ezio Melotti
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
HTMLParser is now able to handle slashes in the start tag.
üst
178e5ea3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
7 deletions
+34
-7
parser.py
Lib/html/parser.py
+11
-7
test_htmlparser.py
Lib/test/test_htmlparser.py
+21
-0
NEWS
Misc/NEWS
+2
-0
No files found.
Lib/html/parser.py
Dosyayı görüntüle @
29877e8e
...
@@ -26,14 +26,18 @@ tagfind = re.compile('[a-zA-Z][-.a-zA-Z0-9:_]*')
...
@@ -26,14 +26,18 @@ tagfind = re.compile('[a-zA-Z][-.a-zA-Z0-9:_]*')
# see http://www.w3.org/TR/html5/tokenization.html#tag-open-state
# see http://www.w3.org/TR/html5/tokenization.html#tag-open-state
# and http://www.w3.org/TR/html5/tokenization.html#tag-name-state
# and http://www.w3.org/TR/html5/tokenization.html#tag-name-state
tagfind_tolerant
=
re
.
compile
(
'[a-zA-Z][^
\t\n\r\f
/>
\x00
]*'
)
tagfind_tolerant
=
re
.
compile
(
'[a-zA-Z][^
\t\n\r\f
/>
\x00
]*'
)
# Note, the strict one of this pair isn't really strict, but we can't
# Note:
# make it correctly strict without breaking backward compatibility.
# 1) the strict attrfind isn't really strict, but we can't make it
# correctly strict without breaking backward compatibility;
# 2) if you change attrfind remember to update locatestarttagend too;
# 3) if you change attrfind and/or locatestarttagend the parser will
# explode, so don't do it.
attrfind
=
re
.
compile
(
attrfind
=
re
.
compile
(
r'\s*([a-zA-Z_][-.:a-zA-Z_0-9]*)(\s*=\s*'
r'\s*([a-zA-Z_][-.:a-zA-Z_0-9]*)(\s*=\s*'
r'(\'[^\']*\'|"[^"]*"|[^\s"\'=<>`]*))?'
)
r'(\'[^\']*\'|"[^"]*"|[^\s"\'=<>`]*))?'
)
attrfind_tolerant
=
re
.
compile
(
attrfind_tolerant
=
re
.
compile
(
r'
\s*((?<=[\'"\s
])[^\s/>][^\s/=>]*)(\s*=+\s*'
r'
[\s/]*((?<=[\'"\s/
])[^\s/>][^\s/=>]*)(\s*=+\s*'
r'(\'[^\']*\'|"[^"]*"|(?![\'"])[^>\s]*))?'
)
r'(\'[^\']*\'|"[^"]*"|(?![\'"])[^>\s]*))?
(?:\s|/(?!>))*
'
)
locatestarttagend
=
re
.
compile
(
r"""
locatestarttagend
=
re
.
compile
(
r"""
<[a-zA-Z][-.a-zA-Z0-9:_]* # tag name
<[a-zA-Z][-.a-zA-Z0-9:_]* # tag name
(?:\s+ # whitespace before attribute name
(?:\s+ # whitespace before attribute name
...
@@ -50,15 +54,15 @@ locatestarttagend = re.compile(r"""
...
@@ -50,15 +54,15 @@ locatestarttagend = re.compile(r"""
"""
,
re
.
VERBOSE
)
"""
,
re
.
VERBOSE
)
locatestarttagend_tolerant
=
re
.
compile
(
r"""
locatestarttagend_tolerant
=
re
.
compile
(
r"""
<[a-zA-Z][-.a-zA-Z0-9:_]* # tag name
<[a-zA-Z][-.a-zA-Z0-9:_]* # tag name
(?:
\s*
# optional whitespace before attribute name
(?:
[\s/]*
# optional whitespace before attribute name
(?:(?<=['"\s
])[^\s/>][^\s/=>]*
# attribute name
(?:(?<=['"\s
/])[^\s/>][^\s/=>]*
# attribute name
(?:\s*=+\s* # value indicator
(?:\s*=+\s* # value indicator
(?:'[^']*' # LITA-enclosed value
(?:'[^']*' # LITA-enclosed value
|"[^"]*" # LIT-enclosed value
|"[^"]*" # LIT-enclosed value
|(?!['"])[^>\s]* # bare value
|(?!['"])[^>\s]* # bare value
)
)
(?:\s*,)* # possibly followed by a comma
(?:\s*,)* # possibly followed by a comma
)?
\s
*
)?
(?:\s|/(?!>))
*
)*
)*
)?
)?
\s* # trailing whitespace
\s* # trailing whitespace
...
...
Lib/test/test_htmlparser.py
Dosyayı görüntüle @
29877e8e
...
@@ -389,6 +389,27 @@ class HTMLParserTolerantTestCase(HTMLParserStrictTestCase):
...
@@ -389,6 +389,27 @@ class HTMLParserTolerantTestCase(HTMLParserStrictTestCase):
self
.
_run_check
(
"<a foo='>'"
,
[(
'data'
,
"<a foo='>'"
)])
self
.
_run_check
(
"<a foo='>'"
,
[(
'data'
,
"<a foo='>'"
)])
self
.
_run_check
(
"<a foo='>"
,
[(
'data'
,
"<a foo='>"
)])
self
.
_run_check
(
"<a foo='>"
,
[(
'data'
,
"<a foo='>"
)])
def
test_slashes_in_starttag
(
self
):
self
.
_run_check
(
'<a foo="var"/>'
,
[(
'startendtag'
,
'a'
,
[(
'foo'
,
'var'
)])])
html
=
(
'<img width=902 height=250px '
'src="/sites/default/files/images/homepage/foo.jpg" '
'/*what am I doing here*/ />'
)
expected
=
[(
'startendtag'
,
'img'
,
[(
'width'
,
'902'
),
(
'height'
,
'250px'
),
(
'src'
,
'/sites/default/files/images/homepage/foo.jpg'
),
(
'*what'
,
None
),
(
'am'
,
None
),
(
'i'
,
None
),
(
'doing'
,
None
),
(
'here*'
,
None
)]
)]
self
.
_run_check
(
html
,
expected
)
html
=
(
'<a / /foo/ / /=/ / /bar/ / />'
'<a / /foo/ / /=/ / /bar/ / >'
)
expected
=
[
(
'startendtag'
,
'a'
,
[(
'foo'
,
None
),
(
'='
,
None
),
(
'bar'
,
None
)]),
(
'starttag'
,
'a'
,
[(
'foo'
,
None
),
(
'='
,
None
),
(
'bar'
,
None
)])
]
self
.
_run_check
(
html
,
expected
)
def
test_declaration_junk_chars
(
self
):
def
test_declaration_junk_chars
(
self
):
self
.
_run_check
(
"<!DOCTYPE foo $ >"
,
[(
'decl'
,
'DOCTYPE foo $ '
)])
self
.
_run_check
(
"<!DOCTYPE foo $ >"
,
[(
'decl'
,
'DOCTYPE foo $ '
)])
...
...
Misc/NEWS
Dosyayı görüntüle @
29877e8e
...
@@ -121,6 +121,8 @@ Core and Builtins
...
@@ -121,6 +121,8 @@ Core and Builtins
Library
Library
-------
-------
- HTMLParser is now able to handle slashes in the start tag.
- Issue #14001: CVE-2012-0845: xmlrpc: Fix an endless loop in
- Issue #14001: CVE-2012-0845: xmlrpc: Fix an endless loop in
SimpleXMLRPCServer upon malformed POST request.
SimpleXMLRPCServer upon malformed POST request.
...
...
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