Permalink
Browse files

Merge pull request #11 from davidcrawford/master

Simple change to escape double quotes when files are included in a double-quoted string.
  • Loading branch information...
2 parents d746c9b + 3284b65 commit da384263999c82ff5747657df8826c4e0b67b44e @NV committed Jul 4, 2012
Showing with 16 additions and 3 deletions.
  1. +3 −0 example/css/quotes.css
  2. +1 −0 example/quotes.js
  3. +2 −2 lib/jspp.rb
  4. +10 −1 spec/jspp_spec.rb
View
@@ -0,0 +1,3 @@
+input[type="submit"] {
+ cursor: pointer;
+}
View
@@ -0,0 +1 @@
+var test = "/*> css/quotes.css */";
View
@@ -7,7 +7,7 @@ def parse text='', base_dir='.'
text.gsub!(INCLUDE_INSIDE_STRING) {
file, dir = get_file $1, base_dir
parsed = parse file, dir
- '"' << parsed.gsub(/$/, '\\').chop << '"'
+ '"' << parsed.gsub(/$/, '\\').gsub(/"/, '\\"').chop << '"'
}
text.gsub!(INCLUDE) {
file, dir = get_file $1, base_dir
@@ -38,4 +38,4 @@ def JSPP path
JSPP.new.parse text, base_dir
end
private :JSPP
-end
+end
View
@@ -35,6 +35,15 @@
it 'returns same text if no /*> file */ was found' do
JSPP.new.parse(PETS).should == PETS
end
+ it 'escapes quotes when loading text inside strings' do
+ file = File.read(EXAMPLE + '/quotes.js')
+ JSPP.new.parse(file, EXAMPLE).should == <<-result
+var test = "input[type=\\"submit\\"] {\\
+ cursor: pointer;\\
+}\\
+";
+ result
+ end
end
describe '#get_file' do
@@ -61,4 +70,4 @@
";
result
end
-end
+end

0 comments on commit da38426

Please sign in to comment.