[IMP] Validate mermaid input before saving

pull/1442/head
Jan Verbeek 2019-10-23 16:03:08 +02:00 committed by Dennis Sluijk
parent 41cc599d92
commit d53fcfe663
1 changed files with 15 additions and 2 deletions

View File

@ -82,13 +82,26 @@ odoo.define('web.web_widget_mermaid', function(require) {
this.$el.html.bind(this.$el) this.$el.html.bind(this.$el)
); );
} catch (e) { } catch (e) {
this.$el.html($('<pre/>').text(e.message)); this.$el.html($('<pre/>').text(e.message || e.str));
} }
// Mermaid uses a temporary div for rendering. It doesn't remove // Mermaid uses a temporary div for rendering. It doesn't remove
// it if an error occurs, and perhaps in other cases too, so get // it if an error occurs, and perhaps in other cases too, so get
// rid of it if it's still around. The id is based on the chartId. // rid of it if it's still around. The id is based on the chartId.
$('#d' + this.chartId).remove(); $('#d' + this.chartId).remove();
} },
_parseValue: function(value) {
if (this.errorMessage) {
this.errorMessage.remove();
}
try {
mermaid.parse(value);
} catch (e) {
this.errorMessage = $('<pre/>').text(e.message || e.str);
this.$el.after(this.errorMessage);
throw e;
}
return value;
},
}); });
field_registry.add('mermaid', MermaidField); field_registry.add('mermaid', MermaidField);