Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Don't use eval for dictionary access. #22

Merged
merged 1 commit into from

2 participants

Jakub Korál Vadim Baryshev
Jakub Korál

Eval is not needed here

Vadim Baryshev
Owner

This eval uses to get access to nested objects. For example:

{
  news : {
    list : '<ul>...</ul>',
    element : '<p>...</p>'
  },
  items : {
    list : '<ul>...</ul>',
    element : '<p>...</p>'
  }
}

With this eval we can access this templates by 'news.list' or 'items.element', without eval we can't do it.

Jakub Korál

Is it ok now?

I'd like to get avoid of the eval here, just because the root can be much much larger than I want to evaluate.

Vadim Baryshev baryshev merged commit 41cd25e into from
Vadim Baryshev
Owner

0.4.11 published. Also i added Array.reduce compatibility function for old browsers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 4, 2013
  1. Jakub Korál
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1  lib/ect.js
2  lib/ect.js
View
@@ -54,7 +54,7 @@
read = function (file) {
if (Object.prototype.toString.call(ect.options.root) === '[object Object]') {
- var data = eval('(ect.options.root.' + file + ')');
+ var data = file.split('.').reduce(function (currentContext, key) { return currentContext[key]; }, ect.options.root);
if (Object.prototype.toString.call(data) === '[object String]') {
return data;
} else {
Something went wrong with that request. Please try again.