Note editor: table inserter doesn't work
Closed this issue · 4 comments
michaelkn commented
It inserts a broken HTML:
<div>
<table collapse;="" margin-left:="" 0px;="" table-layout:="" fixed;="" width:="" 400px;\x22=""><tbody>
<tr><td 1px="" solid="" rgb(219,="" 219,="" 219);="" padding:="" 10="" px;="" margin:="" 0px;="" width:="" 400px;\x22=""><div><br></div></td></tr>
</tbody></table>
</div>
michaelkn commented
It seems that double quote is escaped twice:
2018-01-04 12:00:05.666 MSK libquentier/src/enml/ENMLConverter_p.cpp @ 1532 [Trace]: String before escaping: <div><table style="border-collapse: collapse; margin-left: 0px; table-layout: fixed; width: 400px;" ><tbody><tr><td style="border: 1px solid rgb(219, 219, 219); padding: 10 px; margin: 0px; width: 400px;"><div><br></div></td></tr></tbody></table></div>
2018-01-04 12:00:05.666 MSK libquentier/src/enml/ENMLConverter_p.cpp @ 1538 [Trace]: String after escaping: <div><table style=\x22border-collapse: collapse; margin-left: 0px; table-layout: fixed; width: 400px;\x22 ><tbody><tr><td style=\x22border: 1px solid rgb(219, 219, 219); padding: 10 px; margin: 0px; width: 400px;\x22><div><br></div></td></tr></tbody></table></div>
2018-01-04 12:00:05.666 MSK libquentier/src/note_editor/NoteEditor_p.cpp @ 5326 [Debug]: JS command: managedPageAction('insertHTML', '<div><table style=\\x22border-collapse: collapse; margin-left: 0px; table-layout: fixed; width: 400px;\\x22 ><tbody><tr><td style=\\x22border: 1px solid rgb(219, 219, 219); padding: 10 px; margin: 0px; width: 400px;\\x22><div><br></div></td></tr></tbody></table></div>')
This piece of code causes the problem:
8224 void NoteEditorPrivate::escapeStringForJavaScript(QString & str) const
8225 {
8226 // Escape single and double quotes
8227 ENMLConverter::escapeString(str, /* simplify = */ false);
8228
8229 // Escape all escape sequences to avoid syntax errors
8230 str.replace(QStringLiteral("\\"), QStringLiteral("\\\\"));
First, escapeString
method converts "
into \x22
and then str.replace
adds an additional backslash to it: \\x22
.
michaelkn commented
Btw, \a
escape sequence doesn't exist, see e.g. https://mathiasbynens.be/notes/javascript-escapes
so, a line 8231 str.replace(QStringLiteral("\a"), QStringLiteral("\\a"));
could be omitted.
d1vanov commented
Nice catch!