Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provides narrower regex for conflict marker detect #495

Merged
merged 2 commits into from
Jun 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

##### Bug Fixes

* None.

* Narrows regex for SCM conflict marker detection
[allenhumphreys](https://github.com/allenhumphreys)
[#495](https://github.com/CocoaPods/Xcodeproj/pull/495)

## 1.5.0 (2017-06-06)

Expand Down
11 changes: 9 additions & 2 deletions lib/xcodeproj/plist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,18 @@ def self.autoload_implementation

# @return [Bool] Checks whether there are merge conflicts in the file.
#
# @param [#to_s] path
# @param [#to_s] contents
# The contents of the file.
#
def self.file_in_conflict?(contents)
contents.match(/^(<|=|>){7}/)
conflict_regex = /
^<{7}(?!<) # Exactly 7 left arrows at the beginning of the line
[\w\W]* # Anything
^={7}(?!=) # Exactly 7 equality symbols at the beginning of the line
[\w\W]* # Anything
^>{7}(?!>) # Exactly 7 right arrows at the beginning of the line
/xm
contents.match(conflict_regex)
end
end
end
15 changes: 15 additions & 0 deletions spec/plist_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,21 @@ def o.to_hash
Plist.write_to_path({}, '')
end.should.raise IOError
end

it 'raises when a merge conflict is detected' do
path = 'Sample Project/ProjectInMergeConflict/ProjectInMergeConflict.xcodeproj'
lambda do
Plist.read_from_path(path)
end.should.raise(Xcodeproj::Informative)
end

it 'has reasonably strict detection of conflict markers' do
very_similar = "\n<<<<<<<<\nwords and stuff go here\n========\nother, different words go here\n>>>>>>>>"
Plist.write_to_path({ 'FooterText' => very_similar }, @plist)
lambda do
Plist.read_from_path(@plist)
end.should.not.raise
end
end
end
end