magicdawn / razor-tmpl

razor style template engine for JavaScript
21 stars 9 forks source link

layoutUtil Regex too greedy #3

Open hankor opened 8 years ago

hankor commented 8 years ago

The regex used in layoutUtil to determine the layout name/path seems to be too greedy. If there is another quote followed by a closing bracket somewhere in the page, it'll take the whole text up to that quote as the layout name.

On a page like this for example:

@layout("Layout/Standard.html");
<div>Some content</div>
<script>
    $("#button").click(function() { alert("test"); });
</script>

it would determine

Layout/Standard.html");
<div>Some content</div>
<script>
    $("#button").click(function() { alert("test

as the layout name.

This regex works a lot better for me:

new RegExp(symbol + "layout\\([\\s]*[\"\']{1}([^\"\']*)[\"\']{1}[\\s]*\\);", 'gi')