heroku-nav 0.1.15 → 0.1.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -21,7 +21,7 @@ begin
21
21
  gemspec.add_dependency(%q<rest-client>, [">= 1.0"])
22
22
  gemspec.add_dependency(%q<json>, [">= 0"])
23
23
 
24
- gemspec.version = '0.1.15'
24
+ gemspec.version = '0.1.16'
25
25
  end
26
26
  rescue LoadError
27
27
  puts "Jeweler not available. Install it with: gem install jeweler"
data/heroku-nav.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{heroku-nav}
8
- s.version = "0.1.15"
8
+ s.version = "0.1.16"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Todd Matthews", "Pedro Belo"]
data/lib/heroku/nav.rb CHANGED
@@ -121,8 +121,11 @@ module Heroku
121
121
 
122
122
  def insert!
123
123
  if @nav
124
- @body.send(@body_accessor).gsub!(/(<body.*?>)/i, "\\1#{@nav}")
125
- @headers['Content-Length'] = @body.send(@body_accessor).size.to_s
124
+ match = @body.send(@body_accessor).match(/(\<body[^\>]*\>)/i)
125
+ if match.size > 0
126
+ @body.send(@body_accessor).insert(match.end(0), @nav)
127
+ @headers['Content-Length'] = @body.send(@body_accessor).size.to_s
128
+ end
126
129
  end
127
130
  end
128
131
  end
data/spec/nav_spec.rb CHANGED
@@ -120,4 +120,22 @@ describe Heroku::Nav::Provider do
120
120
  get '/', :body => '<html><body>hi</body>'
121
121
  last_response.body.should.equal '<html><body><!-- heroku header -->hi</body>'
122
122
  end
123
+
124
+ describe "special chars" do
125
+ before do
126
+ Heroku::Nav::Provider.stubs(:fetch).returns('<!-- \+ nav -->')
127
+ end
128
+
129
+ def app
130
+ make_app { use Heroku::Nav::Provider }
131
+ end
132
+
133
+ # tricky situation, the first implementation of Heroku::Nav would inject the
134
+ # html by using gsub. That worked out alright until the html got a sequence of
135
+ # chars like "\+". those got interpreted by gsub and resulted in a bad output
136
+ it "doesn't freakout if the header contains special chars relevant to Ruby's gsub" do
137
+ get '/', :body => '<html><body>hi</body>'
138
+ last_response.body.should.equal '<html><body><!-- \+ nav -->hi</body>'
139
+ end
140
+ end
123
141
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 15
9
- version: 0.1.15
8
+ - 16
9
+ version: 0.1.16
10
10
  platform: ruby
11
11
  authors:
12
12
  - Todd Matthews