Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix script tags to never self close.

  • Loading branch information...
commit 0960c98ebdd7dd769ae0b6a8b9d136579b1a7e26 1 parent 53fad8e
Tim Caswell authored January 11, 2010
11  lib/haml.js
@@ -7,8 +7,8 @@ if (exports) {
7 7
 
8 8
 (function () {
9 9
   
10  
-  var matchers, self_close_tags;
11 10
   
  11
+  var matchers, self_close_tags, no_self_close_tags;
12 12
   function html_escape(text) {
13 13
     if (typeof text !== 'string') {
14 14
       text = text + "";
@@ -126,7 +126,8 @@ if (exports) {
126 126
     return attributes;
127 127
   }
128 128
 
129  
-  self_close_tags = ["meta", "img", "link", "script", "br", "hr"];
  129
+  self_close_tags = ["meta", "img", "link", "br", "hr"];
  130
+  no_self_close_tags = ["script"];
130 131
 
131 132
   // All matchers' regexps should capture leading whitespace in first capture
132 133
   // and trailing content in last capture
@@ -187,8 +188,10 @@ if (exports) {
187 188
           content = '';
188 189
         }
189 190
 
190  
-        if (content.length > 0 && self_close_tags.indexOf(tag) < 0) {
191  
-          return '"<' + tag + attribs + '>" + \n' + content + ' + \n"</' + tag + '>"';
  191
+        if ((content.length > 0 && self_close_tags.indexOf(tag) < 0) || no_self_close_tags.indexOf(tag) >= 0 ) {
  192
+          return '"<' + tag + attribs + '>"' +
  193
+            (content.length > 0 ? ' + \n' + content : "") +
  194
+            ' + \n"</' + tag + '>"';
192 195
         } else {
193 196
           return '"<' + tag + attribs + ' />"';
194 197
         }
8  test/self_close.haml
... ...
@@ -0,0 +1,8 @@
  1
+%html
  2
+  %head
  3
+    :if url !='/'
  4
+      %script
  5
+    %meta{name: "test", value:"Monkey"}
  6
+  %body
  7
+    %a{ href: url }
  8
+      link
2  test/self_close.html
... ...
@@ -0,0 +1,2 @@
  1
+<html><head><script></script><meta name="test" value="Monkey" /></head><body><a href="http://nodejs.org/">link
  2
+</a></body></html>
5  test/self_close.js
... ...
@@ -0,0 +1,5 @@
  1
+{
  2
+  locals: {
  3
+    url: "http://nodejs.org/"
  4
+  }
  5
+}

0 notes on commit 0960c98

Please sign in to comment.
Something went wrong with that request. Please try again.