~carstengrohmann/OOMAnalyser

cce4d65c4f305f1c6499c90110abc8c2f01472e4 — Carsten Grohmann 1 year, 8 months ago 6528b96
Escape special characters in notification box
1 files changed, 16 insertions(+), 2 deletions(-)

M OOMAnalyser.py
M OOMAnalyser.py => OOMAnalyser.py +16 -2
@@ 78,6 78,20 @@ def toggle(element_id):
    element.classList.toggle('js-text--display-none')


def escape_html(unsafe):
    """
    Escape unsafe HTML entities

    @type unsafe: str
    @rtype: str
    """
    return unsafe.replace('&', "&")\
        .replace('<', "&lt;")\
        .replace('>', "&gt;")\
        .replace('"', "&quot;")\
        .replace("'", "&#039;")


def error(msg):
    """Show the error box and add the error message"""
    show_notifybox('ERROR', msg)


@@ 94,7 108,7 @@ def warning(msg):


def show_notifybox(prefix, msg):
    """Show the error box and the message"""
    """Show escaped message in the notification box"""
    if prefix == 'WARNING':
        css_class = 'js-notify_box__msg--warning'
    else:


@@ 103,7 117,7 @@ def show_notifybox(prefix, msg):
    notify_box = document.getElementById('notify_box')
    notification = document.createElement('div')
    notification.classList.add(css_class)
    notification.innerHTML = '{}: {}<br>'.format(prefix, msg)
    notification.innerHTML = '{}: {}<br>'.format(prefix, escape_html(msg))
    notify_box.appendChild(notification)