Skip to content
This repository has been archived by the owner on Jun 9, 2018. It is now read-only.

Commit

Permalink
use a random when encode email address
Browse files Browse the repository at this point in the history
  • Loading branch information
fperrad committed Mar 29, 2009
1 parent 03e121d commit 073db27
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
23 changes: 19 additions & 4 deletions src/Compiler.pir
Expand Up @@ -16,6 +16,8 @@ Markdown::HTML::Compiler implements a compiler for MAST nodes.
.namespace ['Markdown'; 'HTML'; 'Compiler']

.sub '__onload' :anon :load :init
load_bytecode 'Math/Rand.pbc'

$P0 = get_hll_global 'P6metaclass'
$P0 = $P0.'new_class'('Markdown::HTML::Compiler')

Expand Down Expand Up @@ -84,13 +86,26 @@ Markdown::HTML::Compiler implements a compiler for MAST nodes.
L1:
unless $P0 goto L2
$S1 = shift $P0
unless $S1 == ':' goto L3
$S0 .= $S1
goto L1
L3:
if $S1 == '@' goto L_dec
if $S1 == ':' goto L_raw
.local pmc rand
rand = get_hll_global [ 'Math'; 'Rand' ], 'rand'
$I0 = rand()
# roughly 10% raw, 45% hex, 45% dec
$I0 %= 20
if $I0 >= 18 goto L_raw
if $I0 >= 9 goto L_hex
L_dec:
$I1 = ord $S1
$S1 = $I1
$S1 = '&#' . $S1
$S1 .= ';'
goto L_raw
L_hex:
$I1 = ord $S1
$P1[0] = $I1
$S1 = sprintf '&#x%X;', $P1
L_raw:
$S0 .= $S1
goto L1
L2:
Expand Down
2 changes: 1 addition & 1 deletion t/30-autolink.t
Expand Up @@ -31,7 +31,7 @@ language_output_is( 'markdown', <<'CODE', <<'OUT', 'autolink email' );
<somebbob@example.com>
CODE
<p><a href="&#x6D;&#x61;&#x69;&#x6C;&#x74;&#x6F;:&#x73;&#x6F;&#x6D;&#x65;&#x62;&#x62;&#x6F;&#x62;&#x40;&#x65;&#x78;&#x61;&#x6D;&#x70;&#x6C;&#x65;&#x2E;&#x63;&#x6F;&#x6D;">&#x73;&#x6F;&#x6D;&#x65;&#x62;&#x62;&#x6F;&#x62;&#x40;&#x65;&#x78;&#x61;&#x6D;&#x70;&#x6C;&#x65;&#x2E;&#x63;&#x6F;&#x6D;</a></p>
<p><a href="ma&#x69;&#x6C;&#x74;&#111;:&#x73;o&#x6D;&#101;&#x62;&#98;&#111;&#98;&#64;&#101;&#120;&#x61;&#109;&#x70;&#108;&#101;.&#x63;&#x6F;&#109;">&#x73;o&#x6D;&#101;&#x62;&#98;&#111;&#98;&#64;&#101;&#120;&#x61;&#109;&#x70;&#108;&#101;.&#x63;&#x6F;&#109;</a></p>
OUT


Expand Down

0 comments on commit 073db27

Please sign in to comment.