Skip to content

Commit

Permalink
- WIP #5 Improve error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
soywiz committed Mar 3, 2013
1 parent 5b268b9 commit c0583b3
Show file tree
Hide file tree
Showing 7 changed files with 239 additions and 224 deletions.
2 changes: 1 addition & 1 deletion lib/SandboxPolicy.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var SandboxPolicy = (function () {
this.allowedFunctions = [];
this.allowedFilters = [
'upper',
'empty'
'default'
];
}
return SandboxPolicy;
Expand Down
2 changes: 1 addition & 1 deletion lib/SandboxPolicy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export class SandboxPolicy {
allowedTags: string[] = ['for', 'endfor', 'if', 'endif', 'include', 'sandbox', 'endsandbox'];
allowedFunctions: string[] = [];
allowedFilters: string[] = ['upper', 'empty'];
allowedFilters: string[] = ['upper', 'default'];

constructor() {
}
Expand Down
434 changes: 217 additions & 217 deletions lib/parser/TemplateParser.js

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions lib/runtime/RuntimeContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,11 @@ var RuntimeContext = (function () {
return this.$call(this.languageContext.functions, $function, $arguments, $argumentNames);
}
};
RuntimeContext.prototype.filter = function ($function, $arguments) {
return this.$call(this.languageContext.filters, $function, $arguments);
RuntimeContext.prototype.filter = function (filterName, $arguments) {
if(this.languageContext.filters[filterName] === undefined) {
throw (new Error("Invalid filter type '" + filterName + "'"));
}
return this.$call(this.languageContext.filters, filterName, $arguments);
};
RuntimeContext.prototype.test = function ($function, $arguments) {
return this.$call(this.languageContext.tests, $function, $arguments);
Expand Down
5 changes: 3 additions & 2 deletions lib/runtime/RuntimeContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ export class RuntimeContext {
}
}

filter($function: any, $arguments: any[]) {
return this.$call(this.languageContext.filters, $function, $arguments);
filter(filterName: any, $arguments: any[]) {
if (this.languageContext.filters[filterName] === undefined) throw (new Error("Invalid filter type '" + filterName + "'"));
return this.$call(this.languageContext.filters, filterName, $arguments);
}

test($function: any, $arguments: any[]) {
Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/syntax/exceptions/unknown_filter.set
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
=== TITLE
find an unknown filter

=== INPUT
{ }

=== TEMPLATE:main
{{ test|my_unknown_filter }}

=== EXCEPTION
Invalid filter type 'my_unknown_filter'
2 changes: 1 addition & 1 deletion test/fixtures/tags/sandbox/sandbox.set
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ sandbox tag

=== TEMPLATE:sandboxed
{{ __sandboxed|upper }}
{% if not true|empty %}yes{% endif %}
{% if not false|default(false) %}yes{% endif %}

=== TEMPLATE:main
{% sandbox %}
Expand Down

0 comments on commit c0583b3

Please sign in to comment.