-
-
Notifications
You must be signed in to change notification settings - Fork 828
Remove escape backslashes in non-Markdown messages #4694
Remove escape backslashes in non-Markdown messages #4694
Conversation
@@ -42,6 +42,10 @@ export function htmlSerializeIfNeeded(model: EditorModel, {forceHTML = false} = | |||
if (!parser.isPlainText() || forceHTML) { | |||
return parser.toHTML(); | |||
} | |||
// ensure removal of escape backslashes in non-Markdown messages | |||
if (md.indexOf("\\") > -1) { | |||
return parser.toPlaintext(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't this mean we'd lose formatting on stuff like \*hello\* **world**
? ("hello" should be escaped, but world should not)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is caught by the earlier toHTML
call (isPlaintext
returns false for that message), and results in a formatted_body
of *hello* <strong>world</strong>
as expected.
// The default `out` function only sends the input through an XML | ||
// escaping function, which causes messages to be entity encoded, | ||
// which we don't want in this case. | ||
renderer.out = function(s) { | ||
// The `lit` function adds a string literal to the output buffer. | ||
this.lit(s); | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are we accomplishing by removing this? Surely we still want to avoid the encoding the comment describes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the out
function it's overriding:
function out(s) {
this.lit(this.esc(s, false));
}
and esc
:
function(s, preserve_entities) {
if (reXmlSpecial.test(s)) {
if (preserve_entities) {
return s.replace(reXmlSpecialOrEntity, replaceUnsafeChar);
} else {
return s.replace(reXmlSpecial, replaceUnsafeChar);
}
} else {
return s;
}
}
Removing it accounts for this problem. Since toPlaintext
emits HTML (rather unintuitively, given the name), if we don't encode HTML entities they are processed literally.
As an example, if the out
override is left in, the message \*hello\* world '<'
returns a formatted_body
of *hello* world '<'
. Since the message is HTML, Riot produces this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, this seems sane enough to try it. Will merge after the RC is cut just in case.
Iterating on #4008, fixes element-hq/element-web#11230. A couple of changes:
toPlaintext
if there's a backslash present in the message.out
function. As far as I can tell, we do want the messages to be entity-encoded when callingtoPlaintext
(at least, none of the tests broke! 😄).