File: 11_options.t

package info (click to toggle)
libcommonmark-perl 0.310100-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 220 kB
  • sloc: perl: 291; makefile: 3
file content (63 lines) | stat: -rw-r--r-- 1,753 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use strict;
use warnings;

use Encode;
use Test::More tests => 11;

BEGIN {
    use_ok('CommonMark', ':opt');
}

my ($md, $expected);

$md = "aaa\n\nbbb";
$expected = <<'EOF';
<p data-sourcepos="1:1-1:3">aaa</p>
<p data-sourcepos="3:1-3:3">bbb</p>
EOF
is(CommonMark->markdown_to_html($md, OPT_SOURCEPOS), $expected, 'SOURCEPOS');

$md = "a\nb";
is(CommonMark->markdown_to_html($md, OPT_HARDBREAKS), "<p>a<br />\nb</p>\n",
   'HARDBREAKS');
SKIP: {
    skip('NOBREAKS not supported by libcmark', 1)
        if CommonMark->version < 0x001A00;
    is(CommonMark->markdown_to_html($md, OPT_NOBREAKS), "<p>a b</p>\n",
       'NOBREAKS');
}
is(CommonMark->markdown_to_html($md), "<p>a\nb</p>\n",
   'without HARDBREAKS or NOBREAKS');

$md = <<'EOF';
<script>alert('XSS')</script>

a <b/> [link](javascript:alert('XSS'))
EOF
$expected = <<'EOF';
<!-- raw HTML omitted -->
<p>a <!-- raw HTML omitted --> <a href="">link</a></p>
EOF
is(CommonMark->markdown_to_html($md), $expected, 'SAFE is default');
is(CommonMark->markdown_to_html($md, OPT_SAFE|OPT_UNSAFE), $expected,
   'SAFE takes precedence over UNSAFE');
$expected = <<'EOF';
<script>alert('XSS')</script>
<p>a <b/> <a href="javascript:alert(&#x27;XSS&#x27;)">link</a></p>
EOF
is(CommonMark->markdown_to_html($md, OPT_UNSAFE), $expected, 'UNSAFE');

$md = "a\xC0b";
Encode::_utf8_on($md);
is(CommonMark->markdown_to_html($md, OPT_VALIDATE_UTF8), "<p>a\x{FFFD}b</p>\n",
   'VALIDATE_UTF8');
my $html = CommonMark->markdown_to_html($md);
Encode::_utf8_off($html);
is($html, "<p>a\xC0b</p>\n", 'without VALIDATE_UTF8');

$md = q{"a" -- 'b' --- c};
$expected = <<"EOF";
<p>\x{201C}a\x{201D} \x{2013} \x{2018}b\x{2019} \x{2014} c</p>
EOF
is(CommonMark->markdown_to_html($md, OPT_SMART), $expected, 'SMART');