Edgewall Software

Ticket #1457: trac.changeset_content_encoding.patch

File trac.changeset_content_encoding.patch, 2.6 KB (added by vyt@…, 7 years ago)

Patch for correct encoding in changeset content

  • Changeset.py

    diff -ur trac-orig/Changeset.py trac/Changeset.py
    old new  
    200200                        context = int(option[2:]) 
    201201                        break 
    202202                tabwidth = int(self.config.get('diff', 'tab_width')) 
    203                 changes = hdf_diff(util.to_utf8(old_content).splitlines(), 
    204                                    util.to_utf8(new_content).splitlines(), 
     203                changes = hdf_diff(util.to_utf8(old_content,mimeview.get_charset(self, old_node)).splitlines(), 
     204                                   util.to_utf8(new_content,mimeview.get_charset(self, new_node)).splitlines(), 
    205205                                   context, tabwidth, 
    206206                                   ignore_blank_lines='-B' in diff_options[1], 
    207207                                   ignore_case='-i' in diff_options[1], 
     
    234234            new_content = old_content = '' 
    235235            new_node_info = old_node_info = ('','') 
    236236            if old_node: 
    237                 old_content = util.to_utf8(old_node.get_content().read()) 
     237                old_content = util.to_utf8(old_node.get_content().read(),mimeview.get_charset(self, old_node)) 
    238238                old_node_info = (old_node.path, old_node.rev) 
    239239            if mimeview.is_binary(old_content): 
    240240                continue 
    241241            if new_node: 
    242                 new_content = util.to_utf8(new_node.get_content().read()) 
     242                new_content = util.to_utf8(new_node.get_content().read(),mimeview.get_charset(self, new_node)) 
    243243                new_node_info = (new_node.path, new_node.rev) 
    244244            if old_content != new_content: 
    245245                context = 3 
  • mimeview/api.py

    diff -ur trac-orig/mimeview/api.py trac/mimeview/api.py
    old new  
    2424 
    2525from trac.core import * 
    2626 
    27 __all__ = ['get_mimetype', 'is_binary', 'Mimeview'] 
     27__all__ = ['get_mimetype', 'is_binary', 'Mimeview', 'get_charset'] 
    2828 
    2929MIME_MAP = { 
    3030    'css':'text/css', 
     
    9999    except: 
    100100        return None 
    101101 
     102def get_charset(env, node): 
     103    """Get charset for node content""" 
     104    mime_type = node.content_type 
     105    if not mime_type or mime_type == 'application/octet-stream': 
     106        mime_type = get_mimetype(node.name) or mime_type or 'text/plain' 
     107    ctpos = mime_type.find('charset=') 
     108    if ctpos >= 0: 
     109        charset = mime_type[ctpos + 8:] 
     110    else: 
     111        charset = env.config.get('trac', 'default_charset') 
     112    return charset 
     113 
    102114def is_binary(str): 
    103115    """ 
    104116    Try to detect content by checking the first thousand bytes for zeroes.