Permalink
Browse files

Fix script tags to never self close.

  • Loading branch information...
1 parent 53fad8e commit 0960c98ebdd7dd769ae0b6a8b9d136579b1a7e26 @creationix creationix committed Jan 12, 2010
Showing with 22 additions and 4 deletions.
  1. +7 −4 lib/haml.js
  2. +8 −0 test/self_close.haml
  3. +2 −0 test/self_close.html
  4. +5 −0 test/self_close.js
View
11 lib/haml.js
@@ -7,8 +7,8 @@ if (exports) {
(function () {
- var matchers, self_close_tags;
+ var matchers, self_close_tags, no_self_close_tags;
function html_escape(text) {
if (typeof text !== 'string') {
text = text + "";
@@ -126,7 +126,8 @@ if (exports) {
return attributes;
}
- self_close_tags = ["meta", "img", "link", "script", "br", "hr"];
+ self_close_tags = ["meta", "img", "link", "br", "hr"];
+ no_self_close_tags = ["script"];
// All matchers' regexps should capture leading whitespace in first capture
// and trailing content in last capture
@@ -187,8 +188,10 @@ if (exports) {
content = '';
}
- if (content.length > 0 && self_close_tags.indexOf(tag) < 0) {
- return '"<' + tag + attribs + '>" + \n' + content + ' + \n"</' + tag + '>"';
+ if ((content.length > 0 && self_close_tags.indexOf(tag) < 0) || no_self_close_tags.indexOf(tag) >= 0 ) {
+ return '"<' + tag + attribs + '>"' +
+ (content.length > 0 ? ' + \n' + content : "") +
+ ' + \n"</' + tag + '>"';
} else {
return '"<' + tag + attribs + ' />"';
}
View
8 test/self_close.haml
@@ -0,0 +1,8 @@
+%html
+ %head
+ :if url !='/'
+ %script
+ %meta{name: "test", value:"Monkey"}
+ %body
+ %a{ href: url }
+ link
View
2 test/self_close.html
@@ -0,0 +1,2 @@
+<html><head><script></script><meta name="test" value="Monkey" /></head><body><a href="http://nodejs.org/">link
+</a></body></html>
View
5 test/self_close.js
@@ -0,0 +1,5 @@
+{
+ locals: {
+ url: "http://nodejs.org/"
+ }
+}

0 comments on commit 0960c98

Please sign in to comment.