mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Merge pull request #77 from NetAccessCorp/decodeEntities2
further tighten entity-matching regex, add basic test for entity matching
This commit is contained in:
commit
58079ddc2a
@ -32,7 +32,8 @@ var entities = {
|
||||
};
|
||||
|
||||
function decodeEntities(data) {
|
||||
return data.replace(/&([a-z0-9#]+);/gi, function(match, entityName) {
|
||||
// match numeric, hexadecimal & named entities
|
||||
return data.replace(/&(#\d+|#x[0-9a-fA-F]+|[a-zA-Z0-9]+);/g, function(match, entityName) {
|
||||
return entities[entityName] || '${entity:' + entityName + '}';
|
||||
});
|
||||
}
|
||||
|
||||
4
test/compiler-tests.js
Normal file → Executable file
4
test/compiler-tests.js
Normal file → Executable file
@ -58,6 +58,10 @@ describe('marko/compiler' , function() {
|
||||
testCompiler('fixtures/templates/compiler/hello-dynamic');
|
||||
});
|
||||
|
||||
it('should compile a simple template with entities', function() {
|
||||
testCompiler('fixtures/templates/compiler/entities');
|
||||
});
|
||||
|
||||
// it.only('should compile a template with <c:invoke>', function() {
|
||||
// testCompiler('test-project/tabs.marko');
|
||||
// });
|
||||
|
||||
9
test/fixtures/templates/compiler/entities/expected.js
vendored
Executable file
9
test/fixtures/templates/compiler/entities/expected.js
vendored
Executable file
@ -0,0 +1,9 @@
|
||||
exports.create = function(__helpers) {
|
||||
var str = __helpers.s,
|
||||
empty = __helpers.e,
|
||||
notEmpty = __helpers.ne;
|
||||
|
||||
return function render(data, out) {
|
||||
out.w('Hello John & Suzy Invalid Entity: &b ; Valid Numeric Entity: "\nValid Hexadecimal Entity:\n¢');
|
||||
};
|
||||
}
|
||||
4
test/fixtures/templates/compiler/entities/template.marko
vendored
Executable file
4
test/fixtures/templates/compiler/entities/template.marko
vendored
Executable file
@ -0,0 +1,4 @@
|
||||
Hello John & Suzy
|
||||
Invalid Entity: &b ;
|
||||
Valid Numeric Entity: "
|
||||
Valid Hexadecimal Entity: ¢
|
||||
Loading…
x
Reference in New Issue
Block a user