fix(html-parser)!: keep whitespaces in interpolated strings

might be breaking as someone could be relying on this despite being a bug. to fix existing code wrap the string in `html(...)`
This commit is contained in:
alina 🌸 2024-10-07 00:57:15 +03:00
parent 868082260e
commit fefc8d38a7
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI
2 changed files with 12 additions and 2 deletions

View file

@ -361,6 +361,14 @@ describe('HtmlMessageEntityParser', () => {
test(htm`hewwo ${htm`<br>`} world`, [], 'hewwo \nworld')
})
it('should keep whitespaces in raw strings', () => {
const dot = ' ∙ '
const lf = '\n'
test(htm`this is${dot}some text${lf}xd`, [], 'this is ∙ some text\nxd')
test(htm`hewwo ${htm`<br>`} world`, [], 'hewwo \nworld')
})
it('should not ignore newlines and indentation in pre', () => {
test(
htm`<pre>this is some text\n\nwith newlines</pre>`,

View file

@ -262,9 +262,11 @@ function parse(
return
}
if (typeof it === 'string' || typeof it === 'number') {
if (typeof it === 'string') {
processPendingText()
pendingText += it
} else if (Long.isLong(it)) {
processPendingText(false, true)
} else if (Long.isLong(it) || typeof it === 'number') {
pendingText += it.toString(10)
} else {
// TextWithEntities or MessageEntity