Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken eval in _hdlr_field_link_group #11

Open
jayallen opened this issue Dec 7, 2014 · 3 comments
Open

Broken eval in _hdlr_field_link_group #11

jayallen opened this issue Dec 7, 2014 · 3 comments
Assignees

Comments

@jayallen
Copy link
Member

jayallen commented Dec 7, 2014

Using ConfigAssistant 2.3.13 under MT 4.37, I'm getting the following warnings when I try to republish an entire blog:

String found where operator expected at (eval 838) line 1, near "]""" at (eval 838) line 1.
    eval '$value = ""[]""
;' called at addons/ConfigAssistant.pack/lib/ConfigAssistant/Plugin.pm line 738
    ConfigAssistant::Plugin::_hdlr_field_link_group(MT::Component=HASH(0x7fb33499d870), MT::Template::Context=HASH(0x7fb3381b3d50), HASH(0x7fb334f1eba0), HASH(0x7fb3381c8830)) called at addons/ConfigAssistant.pack/lib/ConfigAssistant/Init.pm line 589
    ConfigAssistant::Init::runner("_hdlr_field_link_group", "ConfigAssistant::Plugin", MT::Template::Context=HASH(0x7fb3381b3d50), HASH(0x7fb334f1eba0), HASH(0x7fb3381c8830)) called at addons/ConfigAssistant.pack/lib/ConfigAssistant/Init.pm line 328
    ConfigAssistant::Init::__ANON__(MT::Template::Context=HASH(0x7fb3381b3d50), HASH(0x7fb334f1eba0), HASH(0x7fb3381c8830)) called at lib/MT/Builder.pm line 396
    MT::Builder::build(MT::Builder=HASH(0x7fb333a169c8), MT::Template::Context=HASH(0x7fb3381b3d50), MT::Template::Tokens=ARRAY(0x7fb3381d4d60), undef) called at lib/MT/Template.pm line 269
    MT::Template::build(MT::Template=HASH(0x7fb3339d4ea8), MT::Template::Context=HASH(0x7fb3381b3d50)) called at lib/MT/WeblogPublisher.pm line 1574
    MT::WeblogPublisher::rebuild_indexes(MT::WeblogPublisher=HASH(0x7fb33817a3c0), "BlogID", 1) called at lib/MT.pm line 1509
    MT::rebuild_indexes(MT::App::CMS=HASH(0x7fb333802140), "BlogID", 1) called at lib/MT/CMS/Blog.pm line 662
    MT::CMS::Blog::rebuild_pages(MT::App::CMS=HASH(0x7fb333802140)) called at lib/MT.pm line 2974
    MT::__ANON__(MT::App::CMS=HASH(0x7fb333802140)) called at lib/MT/App.pm line 2715
    eval {...} called at lib/MT/App.pm line 2582
    MT::App::run(MT::App::CMS=HASH(0x7fb333802140)) called at lib/MT/Bootstrap.pm line 135
    eval {...} called at lib/MT/Bootstrap.pm line 76
    MT::Bootstrap::import("MT::Bootstrap", "App", "MT::App::CMS") called at mt.cgi line 11
    main::BEGIN() called at (eval 838) line 1
    eval {...} called at (eval 838) line 1

Line 738 of ConfigAssistant::Plugin is marked below:

sub _hdlr_field_link_group {
    my $plugin = shift;
    my ( $ctx, $args, $cond ) = @_;
    my $field = $ctx->stash('field') or return _no_field($ctx);
    my $value = _get_field_value($ctx);
    $value = '"[]"' if ( !$value || $value eq '' );
    eval "\$value = \"$value\"";            #<------- line 738
    if ($@) { $value = '[]'; }
    my $list = JSON::from_json($value);

Unfortunately, I have no clue what that little piece of Perl gymnastics is intended to accomplish but certainly it should be done differently. Any ideas?

@rujudan
Copy link

rujudan commented May 3, 2016

danwolfgang, and jayallen, has anyone looked at the stash('field') method call? I read up on two good documentations herehttp://template-toolkit.org/docs/modules/Template/Stash/index.html
and herehttp://search.cpan.org/dist/Template-Toolkit/lib/Template/Stash.pm which are both about the stash::* module

@jayallen
Copy link
Member Author

jayallen commented May 3, 2016

@rujudan I haven't seen this particular issue in a long time so there's a good chance that it was being caused by a bug in Movable Type or (more likely) elsewhere in ConfigAssistant and has been subsequently fixed. Are you experiencing it currently?

The $ctx object is not a Template::Toolkit object (MT doesn't use Template::Toolkit) but an MT::Template::Context object (documented here; latest code is here). In any case, the stash method is one of its most widely used and it's very, very simple so I highly doubt that's causing any problems.

Far more likely is the _get_field_value method and the crazy looking handling of a non-true(!?) or empty string value:

$value = '"[]"' if ( !$value || $value eq '' );
eval "\$value = \"$value\"";
if ($@) { $value = '[]'; }

That makes no sense to me why the original author chose to do that (which is why I posted this ticket asking if Dan had any clue). In any case, that piece of code above is definitely a piece of work that needs to be refactored out. And it would have been by now if either of us had seen this error in the time since I posted this but we haven't. If you have, let us know.

@danwolfgang
Copy link
Member

I haven't seen this error before and we do use the link group field with at least one client, FWIW.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants