Giter VIP home page Giter VIP logo

parrot's People

Contributors

e2b avatar ollym avatar rickihastings avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

parrot's Issues

Several Issues

I can't get Parrot working. First, simple examples (as in the Readme) give me the following error:
SyntaxError: Invalid flags supplied to RegExp constructor 'g,m'

Once I changed all of the RegExp constructors to use strings ("gm" or "gmi"), I got this error:
TypeError: Cannot call method 'runInNewContext' of undefined at Object.render (/Users/jacobevelyn/node_modules/parrot/index.js:165:9)

Seems like some big problems are going on here.

Fully implement ERB-like syntax (eRuby)

See ERB in the Ruby documentation:

ERB recognizes certain tags in the provided template and converts them based on the rules below:

<% Ruby code -- inline with output %>
<%= Ruby expression -- replace with result %>
<%# comment -- ignored -- useful in testing %>
% a line of Ruby code -- treated as <% line %> (optional -- see ERB.new)
%% replaced with % if first thing on a line and % processing is used
<%% or %%> -- replace with <% or %> respectively

This also features some escaping for ERB tags.

The trim_mode parameter is interesting, too:

If trim_mode is passed a String containing one or more of the following modifiers, ERB will adjust its code generation as listed:

%  enables Ruby code processing for lines beginning with %
<> omit newline for lines starting with <% and ending in %>
>  omit newline for lines ending in %>

Partial For statement erroring

Hey, Im LOVING this library and using it on my newest project.

It works if I do for example: <%=variable%>

If I do this:

<% for(var i = 0; i < 3; i++) { %>

I am div #<% print(i) %>

<% } %>

It breaks with:

SyntaxError: Unexpected identifier
at Object.render (/node.js/node_modules/parrot/index.js:165:9)
at /node.js/sql.js:54:14
at [object Object]. (fs.js:107:5)
at [object Object].emit (events.js:61:17)
at afterRead (fs.js:878:12)
at wrapper (fs.js:245:17)

Unsafe Regex

The used regular expressions are problematic and will easily break the VM. Here some points:

  • Greedy wildcard matching (.+) instead of a non-greedy one (.+?). This will skip the end tag if another one follows, e.g. <%= var %> foo <%= bar %> becomes print(var %> foo <%= bar);
  • Hardcoded end tag (should be a variable)
  • Can't handle multiline JavaScript in the template tags
  • Can't handle double quotes within JavaScript in the template tags

I'm currently working on a commit, hopefully resolving all bugs. Pull request follows.

Also you might consider releasing a new version of parrot, since the 0.3.0 that can be downloaded via npm is outdated.

Add support for CoffeeScript

This could be easily implemented, we just need to convert the code to real JavaScript after we compiled the input using RegEx.

cache cannot be set to 0

Since you have config.cache = config.cache || exports.config.cache;, you can't set cache to 0, you have to set it to a negative to get a similar effect.

Issue with using double quotes on sandboxed function params

I'm seeing this odd issue, hopefully someone can confirm it.

A - This Fails

SyntaxError: Unexpected token ILLEGAL parrot/index.js:165

var data = "<%= foo(\"bar\") %>";

var view = {
  foo: function(str){ return x(str) }
}

parrot.render(data, {sandbox:view})

B - This Works

var data = "<%= foo('bar') %>";

var view = {
  foo: function(str){ return x(str) }
}

parrot.render(data, {sandbox:view})

B works when I encapsulate the function param 'bar' with single quotes instead of double quotes.

Can anyone else reproduce this?

Write tests

It's not the largest library in the world, this shouldn't be too hard

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.