Permalink
Browse files

Support #x{} and #X{}

The former is pretty escaping. The latter FULL escaping.
  • Loading branch information...
1 parent 589151b commit c3871fee248c39ee5a10cffff54d544f9358cee0 @mxcl committed Mar 15, 2013
Showing with 40 additions and 9 deletions.
  1. +2 −2 BullScript.JSON-tmLanguage
  2. +2 −2 README.md
  3. +4 −2 bsc
  4. +32 −3 tests
@@ -8,7 +8,7 @@
"0": { "name": "string.quoted.double.js" }
},
"patterns": [
- { "begin": "#{",
+ { "begin": "#[nxX]?{",
"end": "}",
"patterns": [
{ "include": "$self" }
@@ -28,7 +28,7 @@
"1": { "name": "entity.name.tag.html" }
},
"patterns": [
- { "begin": "#{",
+ { "begin": "#[nxX]?{",
"end": "}",
"patterns": [
{ "include": "$self" }
View
@@ -13,8 +13,8 @@ something else that is “better”.
Alpha Quality
=============
-The test-suite probably has holes, and some features are not implemented, but
-we’re using it for our projects, so you may like to also.
+The test-suite has holes, and some features are not implemented, but we’re
+using it for our projects, so you may like to also.
Bugs
====
View
@@ -141,12 +141,14 @@ end
class String
def bsubst sep = '"'
- self.gsub(/#([nx]?)\{(.*?)\}/) do
+ self.gsub(/#([nxX]?)\{(.*?)\}/) do
inner = case $1
when 'n'
"((#{$2}) || '')"
+ when 'X'
+ "encodeURIComponent(#{$2}).replace(/[!'()]/g, escape).replace(/\\*/g, '%2A')"
when 'x'
- "encodeURIComponent(#{$2})"
+ "encodeURIComponent(#{$2}).replace('%20', '+')"
else
"(#{$2})"
end
View
@@ -66,7 +66,7 @@ class BullTests < Test::Unit::TestCase
end
def test_URI_encoded_subst
- assert_equal %q{"foo #x{bar} foo"}.to_js, %q{"foo " + encodeURIComponent(bar) + " foo"}
+ assert_equal %q{"foo #x{bar} foo"}.to_js, %q{"foo " + encodeURIComponent(bar).replace('%20', '+') + " foo"}
end
def test_html1
@@ -195,8 +195,23 @@ class BullTests < Test::Unit::TestCase
# assert_equal output, input
# end
+ def test_multiline_with_internal_quotes
+ input = <<-end.to_js
+ """foo
+ bar \#{jee || ''} haha
+ mooface
+ """
+ output = <<-end.to_js
+ 'foo\n'+
+ 'bar ' + (jee || '') + ' haha\n'+
+ 'mooface\n'+
+ ''
+ end
+ assert_equal output, input
+ end
+
def test_misc1
- input = <<-end
+ input = <<-end.to_js
<style>
#content > ul {
-webkit-column-count: 5;
@@ -212,6 +227,20 @@ class BullTests < Test::Unit::TestCase
'} '+
'</style>');
end
- assert_equal input.to_js, output
+ assert_equal output, input.to_js
+ end
+
+ def test_img
+ input = <<-end.to_js
+ var b = 1;
+ <img class=REC src=/static/img/REC.png>;
+ var a = 1;
+ end
+ output = <<-end
+ var b = 1;
+ $('<img class=REC src=/static/img/REC.png>');
+ var a = 1;
+ end
+ assert_equal output, input.to_js
end
end

0 comments on commit c3871fe

Please sign in to comment.