Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Don't use eval for dictionary access. #22

Merged
merged 1 commit into from

2 participants

@kuba-kubula

Eval is not needed here

@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.

@kuba-kubula

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.

@baryshev baryshev merged commit 41cd25e into baryshev:master
@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. @kuba-kubula
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1  lib/ect.js
View
2  lib/ect.js
@@ -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.