Patchwork [STABLE] win32mbcs: wrap underlying pycompat.bytestr to use checkwinfilename safely

login
register
mail settings
Submitter Katsunori FUJIWARA
Date May 12, 2017, 12:50 p.m.
Message ID <71dc8e6d3207dd21de29.1494593437@speaknoevil>
Download mbox | patch
Permalink /patch/20585/
State Accepted
Headers show

Comments

Katsunori FUJIWARA - May 12, 2017, 12:50 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1494593174 -32400
#      Fri May 12 21:46:14 2017 +0900
# Branch stable
# Node ID 71dc8e6d3207dd21de299b2e65c0976ca0b89e9c
# Parent  a0e46f6b248b7a6db0f3cd09b1dba6dcefeb8fd4
win32mbcs: wrap underlying pycompat.bytestr to use checkwinfilename safely

win32mbcs wraps some functions, to prevent them from unintentionally
treating backslash (0x5c), which is used as the second or later byte
of multi bytes characters by problematic encodings, as a path
component delimiter on Windows platform.

This wrapping assumes that wrapped functions can safely accept unicode
string arguments.

Unfortunately, d1937bdcee8c broke this assumption by introducing
pycompat.bytestr() into util.checkwinfilename() for py3 support. After
that, wrapped checkwinfilename() always fails for non-ASCII filename
at pycompat.bytestr() invocation.

This patch wraps underlying pycompat.bytestr() function to use
util.checkwinfilename() safely.

To avoid similar regression in the future, another patch series will
add smoke testing on default branch.
Yuya Nishihara - May 12, 2017, 2:23 p.m.
On Fri, 12 May 2017 21:50:37 +0900, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> # Date 1494593174 -32400
> #      Fri May 12 21:46:14 2017 +0900
> # Branch stable
> # Node ID 71dc8e6d3207dd21de299b2e65c0976ca0b89e9c
> # Parent  a0e46f6b248b7a6db0f3cd09b1dba6dcefeb8fd4
> win32mbcs: wrap underlying pycompat.bytestr to use checkwinfilename safely

Looks good. Queued, thanks.

I believe porting win32mbcs to Python 3 will be tremendously hard. We'll
need redesign.

Patch

diff --git a/hgext/win32mbcs.py b/hgext/win32mbcs.py
--- a/hgext/win32mbcs.py
+++ b/hgext/win32mbcs.py
@@ -155,7 +155,8 @@  funcs = '''os.path.join os.path.split os
 # These functions are required to be called with local encoded string
 # because they expects argument is local encoded string and cause
 # problem with unicode string.
-rfuncs = '''mercurial.encoding.upper mercurial.encoding.lower'''
+rfuncs = '''mercurial.encoding.upper mercurial.encoding.lower
+ mercurial.pycompat.bytestr'''
 
 # List of Windows specific functions to be wrapped.
 winfuncs = '''os.path.splitunc'''