Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

poc for jsml completed

  • Loading branch information...
commit 490cd66c3a79faaaea7eeed9a67070301b6c980b 1 parent 1f8ebff
@jeffsu authored
View
1  CHANGELOG
@@ -1,5 +1,6 @@
0.3.13
* fixed problem that doesn't allow toString methods
+ * fixed string sanitizer problem with double quotes
* JSML POC
0.3.12
View
8 dist/browser/js2-full.js
@@ -312,7 +312,7 @@ function mainFunction (arg) {
REGEX: /^%\{/,
ID: IDS.ISTRING,
sanitize: function(str) {
- return str.replace('"', '\\"');
+ return JSON.stringify(str);
},
consume: function() {
var m = this.tokens.match(this.REGEX);
@@ -326,14 +326,14 @@ function mainFunction (arg) {
if (m) {
var matched = m[1];
if (m[3] == '#{') {
- this.tokens.push([ '"' + this.sanitize(matched) + '"+(', this.ID ]);
+ this.tokens.push([ this.sanitize(matched) + '+(', this.ID ]);
this.tokens.chomp(m[0].length-1);
var block = new JS2.Lexer.Block(this.tokens);
block.tokenize();
this.tokens.push([ ')+', this.ID ]);
toEnd = true;
} else if (m[3] == '}' || m[0] == '}') {
- this.tokens.push([ '"' + this.sanitize(matched) + '"', this.ID ]);
+ this.tokens.push([ this.sanitize(matched), this.ID ]);
this.tokens.chomp(m[0].length);
break;
}
@@ -388,7 +388,7 @@ function mainFunction (arg) {
if (next[1]) {
this.tokens.chomp(next[1].length);
- this.tokens.push([ (first ? '' : '+') + '"' + this.sanitize(next[1]) + '\\n"', IDS.DSTRING ]);
+ this.tokens.push([ (first ? '' : '+') + this.sanitize(next[1]).replace(/"$/, '\\n"') , IDS.DSTRING ]);
}
if (next[3] == '#{') {
View
8 dist/gem/lib/js2/js2.js
@@ -308,7 +308,7 @@ function mainFunction (arg) {
REGEX: /^%\{/,
ID: IDS.ISTRING,
sanitize: function(str) {
- return str.replace('"', '\\"');
+ return JSON.stringify(str);
},
consume: function() {
var m = this.tokens.match(this.REGEX);
@@ -322,14 +322,14 @@ function mainFunction (arg) {
if (m) {
var matched = m[1];
if (m[3] == '#{') {
- this.tokens.push([ '"' + this.sanitize(matched) + '"+(', this.ID ]);
+ this.tokens.push([ this.sanitize(matched) + '+(', this.ID ]);
this.tokens.chomp(m[0].length-1);
var block = new JS2.Lexer.Block(this.tokens);
block.tokenize();
this.tokens.push([ ')+', this.ID ]);
toEnd = true;
} else if (m[3] == '}' || m[0] == '}') {
- this.tokens.push([ '"' + this.sanitize(matched) + '"', this.ID ]);
+ this.tokens.push([ this.sanitize(matched), this.ID ]);
this.tokens.chomp(m[0].length);
break;
}
@@ -384,7 +384,7 @@ function mainFunction (arg) {
if (next[1]) {
this.tokens.chomp(next[1].length);
- this.tokens.push([ (first ? '' : '+') + '"' + this.sanitize(next[1]) + '\\n"', IDS.DSTRING ]);
+ this.tokens.push([ (first ? '' : '+') + this.sanitize(next[1]).replace(/"$/, '\\n"') , IDS.DSTRING ]);
}
if (next[3] == '#{') {
View
8 dist/npm/lib/js2.js
@@ -308,7 +308,7 @@ function mainFunction (arg) {
REGEX: /^%\{/,
ID: IDS.ISTRING,
sanitize: function(str) {
- return str.replace('"', '\\"');
+ return JSON.stringify(str);
},
consume: function() {
var m = this.tokens.match(this.REGEX);
@@ -322,14 +322,14 @@ function mainFunction (arg) {
if (m) {
var matched = m[1];
if (m[3] == '#{') {
- this.tokens.push([ '"' + this.sanitize(matched) + '"+(', this.ID ]);
+ this.tokens.push([ this.sanitize(matched) + '+(', this.ID ]);
this.tokens.chomp(m[0].length-1);
var block = new JS2.Lexer.Block(this.tokens);
block.tokenize();
this.tokens.push([ ')+', this.ID ]);
toEnd = true;
} else if (m[3] == '}' || m[0] == '}') {
- this.tokens.push([ '"' + this.sanitize(matched) + '"', this.ID ]);
+ this.tokens.push([ this.sanitize(matched), this.ID ]);
this.tokens.chomp(m[0].length);
break;
}
@@ -384,7 +384,7 @@ function mainFunction (arg) {
if (next[1]) {
this.tokens.chomp(next[1].length);
- this.tokens.push([ (first ? '' : '+') + '"' + this.sanitize(next[1]) + '\\n"', IDS.DSTRING ]);
+ this.tokens.push([ (first ? '' : '+') + this.sanitize(next[1]).replace(/"$/, '\\n"') , IDS.DSTRING ]);
}
if (next[3] == '#{') {
View
8 flavors/browser-full.js
@@ -312,7 +312,7 @@ function mainFunction (arg) {
REGEX: /^%\{/,
ID: IDS.ISTRING,
sanitize: function(str) {
- return str.replace('"', '\\"');
+ return JSON.stringify(str);
},
consume: function() {
var m = this.tokens.match(this.REGEX);
@@ -326,14 +326,14 @@ function mainFunction (arg) {
if (m) {
var matched = m[1];
if (m[3] == '#{') {
- this.tokens.push([ '"' + this.sanitize(matched) + '"+(', this.ID ]);
+ this.tokens.push([ this.sanitize(matched) + '+(', this.ID ]);
this.tokens.chomp(m[0].length-1);
var block = new JS2.Lexer.Block(this.tokens);
block.tokenize();
this.tokens.push([ ')+', this.ID ]);
toEnd = true;
} else if (m[3] == '}' || m[0] == '}') {
- this.tokens.push([ '"' + this.sanitize(matched) + '"', this.ID ]);
+ this.tokens.push([ this.sanitize(matched), this.ID ]);
this.tokens.chomp(m[0].length);
break;
}
@@ -388,7 +388,7 @@ function mainFunction (arg) {
if (next[1]) {
this.tokens.chomp(next[1].length);
- this.tokens.push([ (first ? '' : '+') + '"' + this.sanitize(next[1]) + '\\n"', IDS.DSTRING ]);
+ this.tokens.push([ (first ? '' : '+') + this.sanitize(next[1]).replace(/"$/, '\\n"') , IDS.DSTRING ]);
}
if (next[3] == '#{') {
View
8 flavors/node.js
@@ -308,7 +308,7 @@ function mainFunction (arg) {
REGEX: /^%\{/,
ID: IDS.ISTRING,
sanitize: function(str) {
- return str.replace('"', '\\"');
+ return JSON.stringify(str);
},
consume: function() {
var m = this.tokens.match(this.REGEX);
@@ -322,14 +322,14 @@ function mainFunction (arg) {
if (m) {
var matched = m[1];
if (m[3] == '#{') {
- this.tokens.push([ '"' + this.sanitize(matched) + '"+(', this.ID ]);
+ this.tokens.push([ this.sanitize(matched) + '+(', this.ID ]);
this.tokens.chomp(m[0].length-1);
var block = new JS2.Lexer.Block(this.tokens);
block.tokenize();
this.tokens.push([ ')+', this.ID ]);
toEnd = true;
} else if (m[3] == '}' || m[0] == '}') {
- this.tokens.push([ '"' + this.sanitize(matched) + '"', this.ID ]);
+ this.tokens.push([ this.sanitize(matched), this.ID ]);
this.tokens.chomp(m[0].length);
break;
}
@@ -384,7 +384,7 @@ function mainFunction (arg) {
if (next[1]) {
this.tokens.chomp(next[1].length);
- this.tokens.push([ (first ? '' : '+') + '"' + this.sanitize(next[1]) + '\\n"', IDS.DSTRING ]);
+ this.tokens.push([ (first ? '' : '+') + this.sanitize(next[1]).replace(/"$/, '\\n"') , IDS.DSTRING ]);
}
if (next[3] == '#{') {
View
8 flavors/ringo-full.js
@@ -310,7 +310,7 @@ function mainFunction (arg) {
REGEX: /^%\{/,
ID: IDS.ISTRING,
sanitize: function(str) {
- return str.replace('"', '\\"');
+ return JSON.stringify(str);
},
consume: function() {
var m = this.tokens.match(this.REGEX);
@@ -324,14 +324,14 @@ function mainFunction (arg) {
if (m) {
var matched = m[1];
if (m[3] == '#{') {
- this.tokens.push([ '"' + this.sanitize(matched) + '"+(', this.ID ]);
+ this.tokens.push([ this.sanitize(matched) + '+(', this.ID ]);
this.tokens.chomp(m[0].length-1);
var block = new JS2.Lexer.Block(this.tokens);
block.tokenize();
this.tokens.push([ ')+', this.ID ]);
toEnd = true;
} else if (m[3] == '}' || m[0] == '}') {
- this.tokens.push([ '"' + this.sanitize(matched) + '"', this.ID ]);
+ this.tokens.push([ this.sanitize(matched), this.ID ]);
this.tokens.chomp(m[0].length);
break;
}
@@ -386,7 +386,7 @@ function mainFunction (arg) {
if (next[1]) {
this.tokens.chomp(next[1].length);
- this.tokens.push([ (first ? '' : '+') + '"' + this.sanitize(next[1]) + '\\n"', IDS.DSTRING ]);
+ this.tokens.push([ (first ? '' : '+') + this.sanitize(next[1]).replace(/"$/, '\\n"') , IDS.DSTRING ]);
}
if (next[3] == '#{') {
View
8 flavors/ruby.js
@@ -308,7 +308,7 @@ function mainFunction (arg) {
REGEX: /^%\{/,
ID: IDS.ISTRING,
sanitize: function(str) {
- return str.replace('"', '\\"');
+ return JSON.stringify(str);
},
consume: function() {
var m = this.tokens.match(this.REGEX);
@@ -322,14 +322,14 @@ function mainFunction (arg) {
if (m) {
var matched = m[1];
if (m[3] == '#{') {
- this.tokens.push([ '"' + this.sanitize(matched) + '"+(', this.ID ]);
+ this.tokens.push([ this.sanitize(matched) + '+(', this.ID ]);
this.tokens.chomp(m[0].length-1);
var block = new JS2.Lexer.Block(this.tokens);
block.tokenize();
this.tokens.push([ ')+', this.ID ]);
toEnd = true;
} else if (m[3] == '}' || m[0] == '}') {
- this.tokens.push([ '"' + this.sanitize(matched) + '"', this.ID ]);
+ this.tokens.push([ this.sanitize(matched), this.ID ]);
this.tokens.chomp(m[0].length);
break;
}
@@ -384,7 +384,7 @@ function mainFunction (arg) {
if (next[1]) {
this.tokens.chomp(next[1].length);
- this.tokens.push([ (first ? '' : '+') + '"' + this.sanitize(next[1]) + '\\n"', IDS.DSTRING ]);
+ this.tokens.push([ (first ? '' : '+') + this.sanitize(next[1]).replace(/"$/, '\\n"') , IDS.DSTRING ]);
}
if (next[3] == '#{') {
View
8 src/core/js2-lexer.js
@@ -131,7 +131,7 @@
REGEX: /^%\{/,
ID: IDS.ISTRING,
sanitize: function(str) {
- return str.replace('"', '\\"');
+ return JSON.stringify(str);
},
consume: function() {
var m = this.tokens.match(this.REGEX);
@@ -145,14 +145,14 @@
if (m) {
var matched = m[1];
if (m[3] == '#{') {
- this.tokens.push([ '"' + this.sanitize(matched) + '"+(', this.ID ]);
+ this.tokens.push([ this.sanitize(matched) + '+(', this.ID ]);
this.tokens.chomp(m[0].length-1);
var block = new JS2.Lexer.Block(this.tokens);
block.tokenize();
this.tokens.push([ ')+', this.ID ]);
toEnd = true;
} else if (m[3] == '}' || m[0] == '}') {
- this.tokens.push([ '"' + this.sanitize(matched) + '"', this.ID ]);
+ this.tokens.push([ this.sanitize(matched), this.ID ]);
this.tokens.chomp(m[0].length);
break;
}
@@ -207,7 +207,7 @@
if (next[1]) {
this.tokens.chomp(next[1].length);
- this.tokens.push([ (first ? '' : '+') + '"' + this.sanitize(next[1]) + '\\n"', IDS.DSTRING ]);
+ this.tokens.push([ (first ? '' : '+') + this.sanitize(next[1]).replace(/"$/, '\\n"') , IDS.DSTRING ]);
}
if (next[3] == '#{') {
View
12 tests/src/jsml.js2
@@ -1,4 +1,3 @@
-console.log('hi');
var text = <<END:jsml
- for (var i=0; i<this.yo.length; i++) {
%div= this.yo[i];
@@ -6,10 +5,13 @@ var text = <<END:jsml
%div.yo
.hello= this.bar
.world
- .world
- .world
- %span{ class: 'hello' } Hello world
+ %span{ class: 'hello', href: "/" } Hello world
= this.hello
END
-console.log(text.result({ hello:"yo", bar:"foo", yo:['hello', 'world'] }));
+js2.test(#(assert) {
+ var result = text.result({ hello:"yo", bar:"foo", yo:['hello', 'world'] });
+ var expected = '<div>hello</div><div>world</div><div class="yo"><div class="hello">foo</div><div class="world"></div></div><span class="hello" href="/">Hello world</span>yo'
+ assert.eq(expected, result);
+});
+
Please sign in to comment.
Something went wrong with that request. Please try again.