Commit c4ef403ac80204346c4cd7114e38107e6807ae3c
1 parent
cab56064
Exists in
master
and in
1 other branch
Strip any query strings from files
Showing
2 changed files
with
22 additions
and
8 deletions
Show diff stats
app/models/backtrace_line_normalizer.rb
| @@ -12,7 +12,12 @@ class BacktraceLineNormalizer | @@ -12,7 +12,12 @@ class BacktraceLineNormalizer | ||
| 12 | if @raw_line['file'].blank? | 12 | if @raw_line['file'].blank? |
| 13 | "[unknown source]" | 13 | "[unknown source]" |
| 14 | else | 14 | else |
| 15 | - @raw_line['file'].to_s.gsub(/\[PROJECT_ROOT\]\/.*\/ruby\/[0-9.]+\/gems/, '[GEM_ROOT]/gems') | 15 | + file = @raw_line['file'].to_s |
| 16 | + # Detect lines from gem | ||
| 17 | + file.gsub!(/\[PROJECT_ROOT\]\/.*\/ruby\/[0-9.]+\/gems/, '[GEM_ROOT]/gems') | ||
| 18 | + # Strip any query strings | ||
| 19 | + file.gsub!(/\?[^\?]*$/, '') | ||
| 20 | + @raw_line['file'] = file | ||
| 16 | end | 21 | end |
| 17 | end | 22 | end |
| 18 | 23 |
spec/models/backtrace_line_normalizer_spec.rb
| @@ -3,16 +3,25 @@ require 'spec_helper' | @@ -3,16 +3,25 @@ require 'spec_helper' | ||
| 3 | describe BacktraceLineNormalizer do | 3 | describe BacktraceLineNormalizer do |
| 4 | subject { described_class.new(raw_line).call } | 4 | subject { described_class.new(raw_line).call } |
| 5 | 5 | ||
| 6 | - describe "sanitize file and method" do | ||
| 7 | - let(:raw_line) { { 'number' => rand(999), 'file' => nil, 'method' => nil } } | 6 | + describe "sanitize" do |
| 7 | + context "unknown file and method" do | ||
| 8 | + let(:raw_line) { { 'number' => rand(999), 'file' => nil, 'method' => nil } } | ||
| 8 | 9 | ||
| 9 | - it "should replace nil file with [unknown source]" do | ||
| 10 | - subject['file'].should == "[unknown source]" | ||
| 11 | - end | 10 | + it "should replace nil file with [unknown source]" do |
| 11 | + subject['file'].should == "[unknown source]" | ||
| 12 | + end | ||
| 12 | 13 | ||
| 13 | - it "should replace nil method with [unknown method]" do | ||
| 14 | - subject['method'].should == "[unknown method]" | 14 | + it "should replace nil method with [unknown method]" do |
| 15 | + subject['method'].should == "[unknown method]" | ||
| 16 | + end | ||
| 15 | end | 17 | end |
| 16 | 18 | ||
| 19 | + context "in app file" do | ||
| 20 | + let(:raw_line) { { 'number' => rand(999), 'file' => "[PROJECT_ROOT]/assets/file.js?body=1", 'method' => nil } } | ||
| 21 | + | ||
| 22 | + it "should strip query strings from files" do | ||
| 23 | + subject['file'].should == "[PROJECT_ROOT]/assets/file.js" | ||
| 24 | + end | ||
| 25 | + end | ||
| 17 | end | 26 | end |
| 18 | end | 27 | end |