Skip to content

Commit

Permalink
Closes #1102
Browse files Browse the repository at this point in the history
  • Loading branch information
justingit committed Jun 28, 2022
1 parent db674f6 commit 4cf84da
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 4 deletions.
73 changes: 72 additions & 1 deletion dada/DADA/App/MassSend.pm
Expand Up @@ -2677,11 +2677,14 @@ sub message_size_check {


sub valid_template_markup_check {

my $self = shift;
my $str = shift;
my $expr = shift || 1; # probably just going to be 1...
my $error_str = undef;



require DADA::Template::Widgets;
my ( $valid, $errors ) = DADA::Template::Widgets::validate_screen(
{
Expand Down Expand Up @@ -2725,6 +2728,74 @@ sub valid_template_markup_check {
return (0, $errors);
}




undef $valid;
undef $errors;

# HTML::Tree does some funky things in the pipeline:
my $n_html;
my $html_tree = 1;

try {
require HTML::Tree;
require HTML::Element;
require HTML::TreeBuilder;

my $root = HTML::TreeBuilder->new(
ignore_unknown => 0,
no_space_compacting => 1,
store_comments => 1,
no_expand_entities => 1,

);

my $html = $str;

$root->parse($html);
$root->eof();
$root->elementify();

# no actual manipulation

$n_html = $root->as_HTML( undef, ' ');
undef $root;
}
catch {
$html_tree = 0;
};

if($html_tree == 1){
require DADA::Template::Widgets;
my ( $valid, $errors ) = DADA::Template::Widgets::validate_screen(
{
-data => \$n_html,
-expr => $expr,
}
);
if ( $valid == 0 ) {
my $munge = quotemeta('/fake/path/for/non/file/template');
$errors =~ s/$munge/line/;
$error_str = $errors . "\n"
. '-' x 72 . "\n"
. $str;
return (0, $errors);
}
}













# Or, everything is cool,
return (1, undef)

Expand Down Expand Up @@ -2783,7 +2854,7 @@ sub report_mass_mail_errors {
},
-screen => 'report_mass_mailing_errors_screen.tmpl',
-vars => {
errors => plaintext_to_html({-str => $errors}),
errors => encode_html_entities($errors),
draft_id => $args->{-draft_id},
draft_role => $args->{-draft_role},
wrap => 1,
Expand Down
14 changes: 12 additions & 2 deletions dada/static/javascripts/dada_mail.js
Expand Up @@ -422,8 +422,11 @@ jQuery(document).ready(function($){

if (content.status === 0){

var return_this = '<p><strong>Problems found:</strong></p><pre>'
+ content.errors
var encoded_errors = encode_html_entities(content.errors);

alert(encoded_errors);
var return_this = '<p><strong>Could not render preview:</strong></p><pre>'
+ encoded_errors
+ '</pre>';

$.colorbox({
Expand Down Expand Up @@ -5593,3 +5596,10 @@ function rand_string() {
return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
}



function encode_html_entities(r) {
return r.replace(/[\x26\x0A\x3c\x3e\x22\x27]/g, function(r) {
return "&#" + r.charCodeAt(0) + ";";
});
}
4 changes: 3 additions & 1 deletion dada/templates/report_mass_mailing_errors_screen.tmpl
Expand Up @@ -8,7 +8,9 @@


<div class="alert-box warning radius">
<!-- tmpl_var errors -->
<pre>
<!-- tmpl_var errors -->
</pre>
</div>

<!-- tmpl_if wrap -->
Expand Down

0 comments on commit 4cf84da

Please sign in to comment.