Issue #3299 resolved

Chinese file name error

Anonymous created an issue

Sorry my English. I want to add a file named 目录.md, and get the message. And using the hg command with cmd is nothing error. But other chinese file name is ok.

** Mercurial version (2.7).  TortoiseHg version (2.9)
** Command: --nofork workbench
** CWD: D:\文字\自言自语
** Encoding: cp936
** Extensions loaded: hggit, hgsubversion, convert, histedit
** Python version: 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)]
** Windows version: sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1')
** Processor architecture: x64
** Qt-4.8.4 PyQt-4.10.2 QScintilla-2.7.2
Traceback (most recent call last):
  File "tortoisehg\hgqt\status.pyo", line 253, in updatePartials
  File "tortoisehg\util\hglib.pyo", line 70, in fromunicode
UnicodeEncodeError: 'gbk' codec can't encode character u'\u013f' in position 0: illegal multibyte sequence

Comments (7)

  1. yyjdelete

    The below code works well with the case, but not sure for other case and encoding

    def _all2unicodeplus(a):
        if isinstance(a, unicode):
            try:
                a.encode('ASCII')
                #NO NEED TO WASTE TIME FOR CONVERTING
                return a
            except UnicodeError:
                try:
                    a = a.encode('utf8')
                except UnicodeError:
                    raise
        #str
        try:
            a = a.decode('ASCII')
            #NO NEED TO WASTE TIME FOR CONVERTING
        except UnicodeDecodeError:
            try:
                while True:
                    a = a.decode('utf8').encode('cp936')
                    #GET THE END
            except UnicodeError:
                #UnicodeDecodeError/UnicodeEncodeError
                try:
                    a = a.decode('cp936')
                except UnicodeError:
                    raise
        return a
    
    def _all2local(a):
        try:
            a = _all2unicodeplus(a).encode('cp936')
        except UnicodeError:
            pass
        return a
    
    def _all2utf8(a):
        try:
            a = _all2unicodeplus(a).encode('utf-8').replace('\0','')
        except UnicodeError:
            pass
        return a
    
  2. Log in to comment