[Rt-commit] rt branch 5.0/outlook-plain-quotes-nested-in-html-stanza created. rt-5.0.2-87-gb7e4def59e
BPS Git Server
git at git.bestpractical.com
Wed Mar 2 20:36:13 UTC 2022
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".
The branch, 5.0/outlook-plain-quotes-nested-in-html-stanza has been created
at b7e4def59ec349636d651c1109167541ce96d89e (commit)
- Log -----------------------------------------------------------------
commit b7e4def59ec349636d651c1109167541ce96d89e
Author: sunnavy <sunnavy at bestpractical.com>
Date: Thu Mar 3 02:42:18 2022 +0800
Test stanza for outlook plain quotes nested in html quotes
diff --git a/t/web/ticket_txn_content.t b/t/web/ticket_txn_content.t
index d092aa9015..1fc05d1fb5 100644
--- a/t/web/ticket_txn_content.t
+++ b/t/web/ticket_txn_content.t
@@ -152,4 +152,60 @@ $form = $m->form_name( 'TicketUpdate' );
$content = $form->find_input( 'UpdateContent' );
like( $content->value, qr/This transaction appears to have no content/, 'no transaction content' );
+$m->goto_create_ticket( $qid );
+$m->submit_form_ok(
+ {
+ form_name => 'TicketCreate',
+ fields => {
+ Subject => 'outlook plain quotes nested in html',
+ ContentType => 'text/html',
+ Content => <<'EOF',
+<div>On Tue Mar 01 18:29:22 2022, root wrote:
+<blockquote>
+<pre>
+replied from outlook
+
+________________________________________
+From: root <root at localhost>
+Sent: Tuesday, March 1, 2022 2:24 PM
+To: rt
+Subject: test mixed quotes
+
+test
+
+</pre>
+</blockquote>
+</div>
+
+<p>test</p>
+EOF
+ },
+ button => 'SubmitTicket',
+ },
+ 'submit TicketCreate form'
+);
+$m->text_like( qr/Ticket \d+ created in queue/, 'ticket is created' );
+$m->content_contains(<<'EOF', 'stanza output' );
+<div class="message-stanza closed"><blockquote>
+
+
+<pre>
+replied from outlook
+</pre>
+<div class="message-stanza open"><blockquote>
+<pre>
+________________________________________
+From: root <root at localhost>
+Sent: Tuesday, March 1, 2022 2:24 PM
+To: rt
+Subject: test mixed quotes
+
+test
+
+</pre>
+
+</blockquote>
+</div></blockquote></div></div>
+EOF
+
done_testing;
commit d166ad08c5cbb57daed683d84409fc611b05642b
Author: sunnavy <sunnavy at bestpractical.com>
Date: Wed Mar 2 05:30:29 2022 +0800
Fix stanza for outlook plain quotes nested in html quotes
When replying an email sent from outlook using CKEditor in web UI, the
generated content is like:
<div>
On Tue Mar 01 18:29:22 2022, root wrote:
<blockquote>
<pre>
replied from outlook
________________________________________
From: root <root at localhost>
Sent: Tuesday, March 1, 2022 2:24 PM
To: rt
Subject: test mixed quotes
test
</pre>
</blockquote>
</div>
Previously the stanza code didn't handle above HTML correctly and
generated the quote part like:
<div class="message-stanza closed">
<blockquote>
<pre>
replied from outlook
<div class="message-stanza open">
________________________________________
From: root <root at localhost>
Sent: Tuesday, March 1, 2022 2:24 PM
To: rt
Subject: test mixed quotes
test
</pre>
</blockquote>
</div>
</div>
The inner <div>'s opening tag is put into <pre>, while its closing tag
is put out of its ancestor <blockquote>. It confuses HTML parser and
causes it to close a <div> ancestor un-intendedly, which breaks layout,
sometimes badly if the snippet occurs multiple times on the page, as it
wrongly closes more <div>s.
This commit fixes the nesting issue and shows outlook quotes correctly:
<div class="message-stanza closed">
<blockquote>
<pre>
replied from outlook
</pre>
<div class="message-stanza open">
<blockquote>
<pre>
________________________________________
From: root <root at localhost>
Sent: Tuesday, March 1, 2022 2:24 PM
To: rt
Subject: test mixed quotes
test
</pre>
</blockquote>
</div>
</blockquote>
</div>
diff --git a/share/html/Elements/ShowMessageStanza b/share/html/Elements/ShowMessageStanza
index 03f80e984a..a2dd3f2470 100644
--- a/share/html/Elements/ShowMessageStanza
+++ b/share/html/Elements/ShowMessageStanza
@@ -119,6 +119,13 @@ AGAIN: foreach ( ; $i < @$Message; $i++ ) {
# need to, we can process it the same way as 'raw'.
$preceding{raw} = substr($stanza->{raw}, 0, $start, '');
+ # If it's wrapped in <pre>(ckeditor does it), we need to complement for the split ones. Here we
+ # close <pre> for the former part. Opening a new <pre> for the latter part is in the else
+ # block.
+ if ( $preceding{raw} =~ /^<pre>/i ) {
+ $preceding{raw} .= '</pre>';
+ }
+
# Replace the current stanza with the two we just created
splice @$Message, $i, 1, \%preceding, $stanza;
@@ -129,7 +136,16 @@ AGAIN: foreach ( ; $i < @$Message; $i++ ) {
} else {
# Nest the current stanza and everything that follows
$stanza->{_outlooked}++;
+
+ # Complement the <pre> for the latter part, see also the if block above.
+ $stanza->{raw} = '<pre>' . $stanza->{raw} if $stanza->{raw} =~ m{</pre>$}i;
$stanza = $Message->[ $i ] = [ splice @$Message, $i ];
+
+ # Wrap the latter part with a new blockquote if the original stanza has it. Note
+ # that </blockquote> in "close_raw" is to close the one in the upper level(original stanza).
+ if ( ref $Message->[0] eq 'HASH' && $Message->[0]{raw} eq '<blockquote>' ) {
+ unshift @$stanza, { %{ $Message->[0] }, close_raw => '</blockquote>' };
+ }
}
}
else {
@@ -158,9 +174,10 @@ AGAIN: foreach ( ; $i < @$Message; $i++ ) {
}
if (@stack) {
+ $m->out('</div>');
+ $m->out( $Message->[0]{close_raw} ) if ref $Message->[0] eq 'HASH' && $Message->[0]{close_raw};
( $Message, $i ) = @{ pop @stack };
$Depth--;
- $m->out('</div>');
goto AGAIN;
}
} else {
-----------------------------------------------------------------------
hooks/post-receive
--
rt
More information about the rt-commit
mailing list