Merge pull request #4138 from lufte/issue4137

Fix double-escaping on qute://log
This commit is contained in:
Jay Kamat 2018-08-18 13:51:10 -07:00 committed by GitHub
commit 9a4f3dae63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 13 deletions

View File

@ -57,6 +57,7 @@ Fixed
- Crash in the `importer.py` script when importing Chrome bookmarks from newer Chrome versions.
- The `content.webrtc_public_interfaces_only` option didn't work on Qt 5.11 previously (it now does).
Note it still does not work on Qt 5.10 (due to a Qt bug) and Qt < 5.9.2.
- Repeated escaping of entries in `qute://log` when refreshing page.
v1.4.1
------

View File

@ -25,6 +25,7 @@ import html as pyhtml
import logging
import contextlib
import collections
import copy
import faulthandler
import traceback
import warnings
@ -568,16 +569,14 @@ class RAMHandler(logging.Handler):
https://github.com/qutebrowser/qutebrowser/issues/34
"""
minlevel = LOG_LEVELS.get(level.upper(), VDEBUG_LEVEL)
lines = []
fmt = self.html_formatter.format if html else self.format
self.acquire()
try:
records = list(self._data)
lines = [fmt(record)
for record in self._data
if record.levelno >= minlevel]
finally:
self.release()
for record in records:
if record.levelno >= minlevel:
lines.append(fmt(record))
return '\n'.join(lines)
def change_log_capacity(self, capacity):
@ -637,17 +636,18 @@ class HTMLFormatter(logging.Formatter):
self._colordict['reset'] = '</font>'
def format(self, record):
record.__dict__.update(self._colordict)
if record.levelname in self._log_colors:
color = self._log_colors[record.levelname]
record.log_color = self._colordict[color]
record_clone = copy.copy(record)
record_clone.__dict__.update(self._colordict)
if record_clone.levelname in self._log_colors:
color = self._log_colors[record_clone.levelname]
record_clone.log_color = self._colordict[color]
else:
record.log_color = ''
record_clone.log_color = ''
for field in ['msg', 'filename', 'funcName', 'levelname', 'module',
'name', 'pathname', 'processName', 'threadName']:
data = str(getattr(record, field))
setattr(record, field, pyhtml.escape(data))
msg = super().format(record)
data = str(getattr(record_clone, field))
setattr(record_clone, field, pyhtml.escape(data))
msg = super().format(record_clone)
if not msg.endswith(self._colordict['reset']):
msg += self._colordict['reset']
return msg