Skip to content

Commit 569fe81

Browse files
committed
html: add "Microsoft Outlook comment" tests
This only adds new tests. A follow-up commit will change behavior. Updates golang/go#58246 Change-Id: I6adf5941d5cfd3c28f7b9328882ac280109ee028 Reviewed-on: https://go-review.googlesource.com/c/net/+/469055 TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Nigel Tao <[email protected]> Reviewed-by: Kunpei Sakai <[email protected]> Reviewed-by: Damien Neil <[email protected]> Reviewed-by: Bryan Mills <[email protected]>
1 parent 8e2b117 commit 569fe81

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

html/token_test.go

+90
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,24 @@ import (
1414
"testing"
1515
)
1616

17+
// https://github.com/golang/go/issues/58246
18+
const issue58246 = `<!--[if gte mso 12]>
19+
<xml>
20+
<o:OfficeDocumentSettings>
21+
<o:AllowPNG/>
22+
<o:PixelsPerInch>96</o:PixelsPerInch>
23+
</o:OfficeDocumentSettings>
24+
</xml>
25+
<![endif]-->`
26+
const issue58246Rendered = `<!--[if gte mso 12]&gt;
27+
&lt;xml&gt;
28+
&lt;o:OfficeDocumentSettings&gt;
29+
&lt;o:AllowPNG/&gt;
30+
&lt;o:PixelsPerInch&gt;96&lt;/o:PixelsPerInch&gt;
31+
&lt;/o:OfficeDocumentSettings&gt;
32+
&lt;/xml&gt;
33+
&lt;![endif]-->`
34+
1735
type tokenTest struct {
1836
// A short description of the test case.
1937
desc string
@@ -411,6 +429,78 @@ var tokenTests = []tokenTest{
411429
"a<!--!--!<--!-->z",
412430
"a$<!--!--!&lt;--!-->$z",
413431
},
432+
{
433+
"comment23",
434+
"a<!--&gt;-->z",
435+
"a$<!--&gt;-->$z",
436+
},
437+
{
438+
"comment24",
439+
"a<!--&gt;>x",
440+
"a$<!--&gt;&gt;x-->",
441+
},
442+
{
443+
"comment25",
444+
"a<!--&gt;&gt;",
445+
"a$<!--&gt;&gt;-->",
446+
},
447+
{
448+
"comment26",
449+
"a<!--&gt;&gt;-",
450+
"a$<!--&gt;&gt;-->",
451+
},
452+
{
453+
"comment27",
454+
"a<!--&gt;&gt;-->z",
455+
"a$<!--&gt;&gt;-->$z",
456+
},
457+
{
458+
"comment28",
459+
"a<!--&amp;&gt;-->z",
460+
"a$<!--&amp;&gt;-->$z",
461+
},
462+
{
463+
"comment29",
464+
"a<!--&amp;gt;-->z",
465+
"a$<!--&amp;gt;-->$z",
466+
},
467+
{
468+
"comment30",
469+
"a<!--&nosuchentity;-->z",
470+
"a$<!--&amp;nosuchentity;-->$z",
471+
},
472+
// https://stackoverflow.design/email/base/mso/#targeting-specific-outlook-versions
473+
// says "[For] Windows Outlook 2003 and above... conditional comments allow
474+
// us to add bits of HTML that are only read by the Word-based versions of
475+
// Outlook". TODO: these comments (with angle brackets) should pass through
476+
// unchanged (by this Go package) when rendering.
477+
//
478+
// We should also still escape ">" as "&gt;" when necessary.
479+
// https://github.com/golang/go/issues/48237
480+
//
481+
// The "your code" example below comes from that stackoverflow.design link
482+
// above but note that it can contain angle-bracket-rich XML.
483+
// https://github.com/golang/go/issues/58246
484+
{
485+
"issue48237CommentWithAmpgtsemi1",
486+
"a<!--<p></p>&lt;!--[video]--&gt;-->z",
487+
"a$<!--&lt;p&gt;&lt;/p&gt;&lt;!--[video]--&gt;-->$z",
488+
},
489+
{
490+
"issue48237CommentWithAmpgtsemi2",
491+
"a<!--<p></p>&lt;!--[video]--!&gt;-->z",
492+
"a$<!--&lt;p&gt;&lt;/p&gt;&lt;!--[video]--!&gt;-->$z",
493+
},
494+
{
495+
"issue58246MicrosoftOutlookComment1",
496+
"a<!--[if mso]> your code <![endif]-->z",
497+
"a$<!--[if mso]&gt; your code &lt;![endif]-->$z",
498+
},
499+
{
500+
"issue58246MicrosoftOutlookComment2",
501+
"a" + issue58246 + "z",
502+
"a$" + issue58246Rendered + "$z",
503+
},
414504
// An attribute with a backslash.
415505
{
416506
"backslash",

0 commit comments

Comments
 (0)