Skip to content

Commit b3b9a46

Browse files
committed
Merge pull request #1358 from rwstauner/dirs-with-spaces
Match file paths with spaces in caller regexp
2 parents 97ab805 + 90fa377 commit b3b9a46

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Features:
2727
Fixes:
2828
- [#1239](https://github.com/rails-api/active_model_serializers/pull/1239) Fix duplicates in JSON API compound documents (@beauby)
2929
- [#1214](https://github.com/rails-api/active_model_serializers/pull/1214) retrieve the key from the reflection options when building associations (@NullVoxPopuli, @hut8)
30+
- [#1358](https://github.com/rails-api/active_model_serializers/pull/1358) Handle serializer file paths with spaces (@rwstauner, @bf4)
3031

3132
Misc:
3233
- [#1233](https://github.com/rails-api/active_model_serializers/pull/1233) Top-level meta and meta_key options no longer handled at serializer level (@beauby)

lib/active_model/serializer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Serializer
2323
# c/git/emberjs/ember-crm-backend/app/serializers/lead_serializer.rb
2424
CALLER_FILE = /
2525
\A # start of string
26-
\S+ # one or more non-spaces
26+
.+ # file path (one or more characters)
2727
(?= # stop previous match when
2828
:\d+ # a colon is followed by one or more digits
2929
:in # followed by a colon followed by in

test/serializers/cache_test.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'test_helper'
2+
require 'tmpdir'
23
require 'tempfile'
34
module ActiveModel
45
class Serializer
@@ -160,16 +161,31 @@ def test_serializer_file_path_on_windows
160161
assert_equal caller_line[ActiveModel::Serializer::CALLER_FILE], path
161162
end
162163

164+
def test_serializer_file_path_with_space
165+
path = '/Users/git/ember js/ember-crm-backend/app/serializers/lead_serializer.rb'
166+
caller_line = "#{path}:1:in `<top (required)>'"
167+
assert_equal caller_line[ActiveModel::Serializer::CALLER_FILE], path
168+
end
169+
170+
def test_serializer_file_path_with_submatch
171+
# The submatch in the path ensures we're using a correctly greedy regexp.
172+
path = '/Users/git/ember js/ember:123:in x/app/serializers/lead_serializer.rb'
173+
caller_line = "#{path}:1:in `<top (required)>'"
174+
assert_equal caller_line[ActiveModel::Serializer::CALLER_FILE], path
175+
end
176+
163177
def test_digest_caller_file
164178
contents = "puts 'AMS rocks'!"
165-
file = Tempfile.new('some_ruby.rb')
179+
dir = Dir.mktmpdir('space char')
180+
file = Tempfile.new('some_ruby.rb', dir)
166181
file.write(contents)
167182
path = file.path
168183
caller_line = "#{path}:1:in `<top (required)>'"
169184
file.close
170185
assert_equal ActiveModel::Serializer.digest_caller_file(caller_line), Digest::MD5.hexdigest(contents)
171186
ensure
172187
file.unlink
188+
FileUtils.remove_entry dir
173189
end
174190

175191
def test_warn_on_serializer_not_defined_in_file

0 commit comments

Comments
 (0)