Permalink
Browse files

Do not replace @ when it's within a String with double quotes, issue #6

  • Loading branch information...
1 parent f244eb4 commit 91cf0de1ceb0720d9ea3d2bec5eb6e8777ac1574 @solso committed Jan 26, 2013
Showing with 15 additions and 3 deletions.
  1. +3 −3 lib/swagger_reader.rb
  2. +4 −0 test/data/sample6.rb
  3. +8 −0 test/unit/swagger_reader_test.rb
View
@@ -46,13 +46,13 @@ def sort_for_vars_declaration(code)
cont = 0
code[:code].each do |code_line|
- code_line.strip!
+ code_line.strip!
if code_line[0]=="@"[0]
- tmp_vars[:code] << code_line.gsub('@',' ')
+ tmp_vars[:code] << code_line.gsub(/@(?=([^"]*"[^"]*")*[^"]*$)/," ")
tmp_vars[:line_number] << code[:line_number][cont]
tmp_vars[:file] << code[:file][cont]
else
- tmp_not_vars[:code] << code_line.gsub('@',' ')
+ tmp_not_vars[:code] << code_line.gsub(/@(?=([^"]*"[^"]*")*[^"]*$)/," ")
tmp_not_vars[:line_number] << code[:line_number][cont]
tmp_not_vars[:file] << code[:file][cont]
end
View
@@ -0,0 +1,4 @@
+##~ sapi = source2swagger.namespace("sentiment")
+##~ sapi.basePath = "<%= @base_path %>"
+##~ sapi.swagrVersion = "0.1a"
+##~ sapi.apiVersion = "1.0"
@@ -177,5 +177,13 @@ def test_safe_level
reader.process_code(code)
end
end
+
+ def test_missing_ad_sign
+ ## https://github.com/solso/source2swagger/issues/6
+ reader = SwaggerReader.new
+ code = reader.analyze_file("#{File.dirname(__FILE__)}/../data/sample6.rb","##~")
+ api1 = reader.process_code(code)
+ assert_equal "<%= @base_path %>", api1["sentiment"][:basePath]
+ end
end

0 comments on commit 91cf0de

Please sign in to comment.