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
4f35c715
Kaydet (Commit)
4f35c715
authored
Eki 06, 2004
tarafından
Brett Cannon
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Locale data that contains regex metacharacters are now properly escaped.
Closes bug #1039270.
üst
579b3e24
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
2 deletions
+22
-2
_strptime.py
Lib/_strptime.py
+4
-2
test_strptime.py
Lib/test/test_strptime.py
+13
-0
NEWS
Misc/NEWS
+5
-0
No files found.
Lib/_strptime.py
Dosyayı görüntüle @
4f35c715
...
...
@@ -15,6 +15,7 @@ import locale
import
calendar
from
re
import
compile
as
re_compile
from
re
import
IGNORECASE
from
re
import
escape
as
re_escape
from
datetime
import
date
as
datetime_date
try
:
from
thread
import
allocate_lock
as
_thread_allocate_lock
...
...
@@ -232,7 +233,7 @@ class TimeRE(dict):
return
''
to_convert
=
to_convert
[:]
to_convert
.
sort
(
key
=
len
,
reverse
=
True
)
regex
=
'|'
.
join
(
to_convert
)
regex
=
'|'
.
join
(
re_escape
(
stuff
)
for
stuff
in
to_convert
)
regex
=
'(?P<
%
s>
%
s'
%
(
directive
,
regex
)
return
'
%
s)'
%
regex
...
...
@@ -245,7 +246,8 @@ class TimeRE(dict):
"""
processed_format
=
''
# The sub() call escapes all characters that might be misconstrued
# as regex syntax.
# as regex syntax. Cannot use re.escape since we have to deal with
# format directives (%m, etc.).
regex_chars
=
re_compile
(
r"([\\.^$*+?\(\){}\[\]|])"
)
format
=
regex_chars
.
sub
(
r"\\\1"
,
format
)
whitespace_replacement
=
re_compile
(
'
\
s+'
)
...
...
Lib/test/test_strptime.py
Dosyayı görüntüle @
4f35c715
...
...
@@ -176,6 +176,19 @@ class TimeRETests(unittest.TestCase):
found
=
compiled_re
.
match
(
"
\
w+ 10"
)
self
.
failUnless
(
found
,
"Escaping failed of format '
\
w+ 10'"
)
def
test_locale_data_w_regex_metacharacters
(
self
):
# Check that if locale data contains regex metacharacters they are
# escaped properly.
# Discovered by bug #1039270 .
locale_time
=
_strptime
.
LocaleTime
()
locale_time
.
timezone
=
(
frozenset
((
"utc"
,
"gmt"
,
"Tokyo (standard time)"
)),
frozenset
(
"Tokyo (daylight time)"
))
time_re
=
_strptime
.
TimeRE
(
locale_time
)
self
.
failUnless
(
time_re
.
compile
(
"
%
Z"
)
.
match
(
"Tokyo (standard time)"
),
"locale data that contains regex metacharacters is not"
" properly escaped"
)
class
StrptimeTests
(
unittest
.
TestCase
):
"""Tests for _strptime.strptime."""
...
...
Misc/NEWS
Dosyayı görüntüle @
4f35c715
...
...
@@ -34,6 +34,11 @@ Extension modules
Library
-------
-
time
.
strptime
()
now
properly
escapes
timezones
and
all
other
locale
-
specific
strings
for
regex
-
specific
symbols
.
Was
breaking
under
Japanese
Windows
when
the
timezone
was
specified
as
"Tokyo (standard time)"
.
Closes
bug
#
1039270.
-
Updates
for
the
email
package
:
+
All
deprecated
APIs
that
in
email
2.
x
issued
warnings
have
been
removed
:
_encoder
argument
to
the
MIMEText
constructor
,
Message
.
add_payload
(),
...
...
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