Skip to content

Commit

Permalink
Do not replace @ when it's within a String with double quotes, issue #6
Browse files Browse the repository at this point in the history
  • Loading branch information
solso committed Jan 26, 2013
1 parent f244eb4 commit 91cf0de
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/swagger_reader.rb
Expand Up @@ -46,13 +46,13 @@ def sort_for_vars_declaration(code)


cont = 0 cont = 0
code[:code].each do |code_line| code[:code].each do |code_line|
code_line.strip! code_line.strip!
if code_line[0]=="@"[0] 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[:line_number] << code[:line_number][cont]
tmp_vars[:file] << code[:file][cont] tmp_vars[:file] << code[:file][cont]
else 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[:line_number] << code[:line_number][cont]
tmp_not_vars[:file] << code[:file][cont] tmp_not_vars[:file] << code[:file][cont]
end end
Expand Down
4 changes: 4 additions & 0 deletions test/data/sample6.rb
@@ -0,0 +1,4 @@
##~ sapi = source2swagger.namespace("sentiment")
##~ sapi.basePath = "<%= @base_path %>"
##~ sapi.swagrVersion = "0.1a"
##~ sapi.apiVersion = "1.0"
8 changes: 8 additions & 0 deletions test/unit/swagger_reader_test.rb
Expand Up @@ -177,5 +177,13 @@ def test_safe_level
reader.process_code(code) reader.process_code(code)
end end
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 end

0 comments on commit 91cf0de

Please sign in to comment.