Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
6e1b832a
Commit
6e1b832a
authored
May 23, 2017
by
Xiang Zhang
Committed by
GitHub
May 23, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-30003: Fix handling escape characters in HZ codec (#1720) (#1556)
parent
2b67c7aa
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
13 deletions
+21
-13
Lib/test/test_codecencodings_cn.py
Lib/test/test_codecencodings_cn.py
+4
-0
Misc/NEWS
Misc/NEWS
+3
-0
Modules/cjkcodecs/_codecs_cn.c
Modules/cjkcodecs/_codecs_cn.c
+14
-13
No files found.
Lib/test/test_codecencodings_cn.py
View file @
6e1b832a
...
...
@@ -82,6 +82,10 @@ class Test_HZ(test_multibytecodec_support.TestBase, unittest.TestCase):
(
b'ab~cd'
,
'replace'
,
u'ab
\
uFFFD
d'
),
(
b'ab
\
xff
cd'
,
'replace'
,
u'ab
\
uFFFD
cd'
),
(
b'ab~{
\
x81
\
x81
\
x41
\
x44
~}cd'
,
'replace'
,
u'ab
\
uFFFD
\
uFFFD
\
u804A
cd'
),
# issue 30003
(
u'ab~cd'
,
'strict'
,
b'ab~~cd'
),
# escape ~
(
b'~{Dc~~:C~}'
,
'strict'
,
None
),
# ~~ only in ASCII mode
(
b'~{Dc~
\
n
:C~}'
,
'strict'
,
None
),
# ~\n only in ASCII mode
)
def
test_main
():
...
...
Misc/NEWS
View file @
6e1b832a
...
...
@@ -49,6 +49,9 @@ Extension Modules
Library
-------
- bpo-30003: Fix handling escape characters in HZ codec. Based on patch
by Ma Lin.
- bpo-30375: Warnings emitted when compile a regular expression now always
point to the line in the user code. Previously they could point into inners
of the re module if emitted from inside of groups or conditionals.
...
...
Modules/cjkcodecs/_codecs_cn.c
View file @
6e1b832a
...
...
@@ -335,15 +335,17 @@ ENCODER(hz)
DBCHAR
code
;
if
(
c
<
0x80
)
{
if
(
state
->
i
==
0
)
{
WRITE1
((
unsigned
char
)
c
)
NEXT
(
1
,
1
)
}
else
{
WRITE3
(
'~'
,
'}'
,
(
unsigned
char
)
c
)
NEXT
(
1
,
3
)
if
(
state
->
i
)
{
WRITE2
(
'~'
,
'}'
)
NEXT_OUT
(
2
)
state
->
i
=
0
;
}
WRITE1
((
unsigned
char
)
c
)
NEXT
(
1
,
1
)
if
(
c
==
'~'
)
{
WRITE1
(
'~'
)
NEXT_OUT
(
1
)
}
continue
;
}
...
...
@@ -390,20 +392,19 @@ DECODER(hz)
unsigned
char
c2
=
IN2
;
REQUIRE_INBUF
(
2
)
if
(
c2
==
'~'
)
{
if
(
c2
==
'~'
&&
state
->
i
==
0
)
{
WRITE1
(
'~'
)
NEXT
(
2
,
1
)
continue
;
NEXT_OUT
(
1
)
}
else
if
(
c2
==
'{'
&&
state
->
i
==
0
)
state
->
i
=
1
;
/* set GB */
else
if
(
c2
==
'\n'
&&
state
->
i
==
0
)
;
/* line-continuation */
else
if
(
c2
==
'}'
&&
state
->
i
==
1
)
state
->
i
=
0
;
/* set ASCII */
else
if
(
c2
==
'\n'
)
;
/* line-continuation */
else
return
2
;
NEXT
(
2
,
0
);
NEXT
_IN
(
2
)
continue
;
}
...
...
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