# Buggy code
def delete_office_registrymodifications(path):
    """Erase LibreOffice 3.4 and Apache OpenOffice.org 3.4 MRU in registrymodifications.xcu"""
    import xml.dom.minidom

    dom1 = xml.dom.minidom.parse(path)
    modified = False
    for node in dom1.getElementsByTagName("item"):
        if not node.hasAttribute("oor:path"):
            continue
        if not node.getAttribute("oor:path").startswith(
            "/org.openoffice.Office.Histories/Histories/"
        ):
            continue
        node.parentNode.removeChild(node)
        node.unlink()
        modified = True
    if modified:
        with open(path, "w") as xml_file:
            dom1.writexml(xml_file)


# Traceback (UnicodeDecodeError)
Błąd: google_chrome.cache: Command to clean JSON file, path=C:\Users\UserXXX\AppData\Local\Google\Chrome\User Data\Default\Preferences, address=dns_prefetching/host_referral_list
Traceback (most recent call last):
File "C:\projects\bleachbit\bleachbit\Worker.py", line 87, in execute
File "C:\projects\bleachbit\bleachbit\Command.py", line 244, in execute
File "C:\projects\bleachbit\bleachbit\FileUtilities.py", line 263, in clean_json
File "C:\Python34\lib\json\__init__.py", line 265, in load
File "C:\Python34\lib\encodings\cp1250.py", line 23, in decode
UnicodeDecodeError: 'charmap' codec can't decode byte 0x98 in position 28203: character maps to <undefined>
Błąd: google_chrome.cache: Command to clean JSON file, path=C:\Users\UserXXX\AppData\Local\Google\Chrome\User Data\Default\Preferences, address=dns_prefetching/startup_list
Traceback (most recent call last):
File "C:\projects\bleachbit\bleachbit\Worker.py", line 87, in execute
File "C:\projects\bleachbit\bleachbit\Command.py", line 244, in execute
File "C:\projects\bleachbit\bleachbit\FileUtilities.py", line 263, in clean_json
File "C:\Python34\lib\json\__init__.py", line 265, in load
File "C:\Python34\lib\encodings\cp1250.py", line 23, in decode
UnicodeDecodeError: 'charmap' codec can't decode byte 0x98 in position 28203: character maps to <undefined>
Błąd: google_chrome.cache: Command to clean JSON file, path=C:\Users\UserXXX\AppData\Local\Google\Chrome\User Data\Default\Preferences, address=net/http_server_properties/servers
Traceback (most recent call last):
File "C:\projects\bleachbit\bleachbit\Worker.py", line 87, in execute
File "C:\projects\bleachbit\bleachbit\Command.py", line 244, in execute
File "C:\projects\bleachbit\bleachbit\FileUtilities.py", line 263, in clean_json
File "C:\Python34\lib\json\__init__.py", line 265, in load
File "C:\Python34\lib\encodings\cp1250.py", line 23, in decode
UnicodeDecodeError: 'charmap' codec can't decode byte 0x98 in position 28203: character maps to <undefined>

# Fixed code
def delete_office_registrymodifications(path):
    """Erase LibreOffice 3.4 and Apache OpenOffice.org 3.4 MRU in registrymodifications.xcu"""
    import xml.dom.minidom

    dom1 = xml.dom.minidom.parse(path)
    modified = False
    for node in dom1.getElementsByTagName("item"):
        if not node.hasAttribute("oor:path"):
            continue
        if not node.getAttribute("oor:path").startswith(
            "/org.openoffice.Office.Histories/Histories/"
        ):
            continue
        node.parentNode.removeChild(node)
        node.unlink()
        modified = True
    if modified:
        with open(path, "w", encoding="utf-8") as xml_file:
            dom1.writexml(xml_file)