Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2004 from kareila/1990-markdown-usernames
[#1990] don't transform username tags in URLs
- Loading branch information
Showing
2 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# t/cleaner-markdown.t | ||
# | ||
# Test LJ::CleanHTML with Markdown text. | ||
# | ||
# Authors: | ||
# Jen Griffin <kareila@livejournal.com> | ||
# | ||
# Copyright (c) 2017 by Dreamwidth Studios, LLC. | ||
# | ||
# This program is free software; you may redistribute it and/or modify it under | ||
# the same terms as Perl itself. For a copy of the license, please reference | ||
# 'perldoc perlartistic' or 'perldoc perlgpl'. | ||
# | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Test::More tests => 4; | ||
|
||
BEGIN { $LJ::_T_CONFIG = 1; require "$ENV{LJHOME}/cgi-bin/ljlib.pl"; } | ||
use LJ::CleanHTML; | ||
|
||
my $lju_sys = LJ::ljuser("system"); | ||
my $url = 'https://medium.com/@username/title-of-page'; | ||
|
||
my $as_markdown = sub { return "!markdown\n$_[0]" }; | ||
|
||
my $clean = sub { | ||
my ( $text ) = @_; | ||
$text = $as_markdown->( $text ); | ||
LJ::CleanHTML::clean_event( \$text, { wordlength => 80 } ); | ||
chomp $text; | ||
return $text; | ||
}; | ||
|
||
# plain text user tag | ||
is( $clean->('@system'), "<p>$lju_sys</p>", | ||
"user tag in plain text converted" ); | ||
|
||
# plain URL containing user tag | ||
# (Markdown conversion sets preformatted flag, so this won't linkify) | ||
is( $clean->($url), "<p>$url</p>", | ||
"user tag in URL not converted" ); | ||
|
||
# linked URL containing user tag | ||
is( $clean->("[link from \@system]($url)"), | ||
qq{<p><a href="$url">link from $lju_sys</a></p>}, | ||
"user tag in href not converted, but user tag in link text converted []" ); | ||
|
||
# same as standard HTML | ||
is( $clean->(qq{<a href="$url">link from \@system</a>}), | ||
qq{<p><a href="$url">link from $lju_sys</a></p>}, | ||
"user tag in href not converted, but user tag in link text converted <>" ); |