File tree Expand file tree Collapse file tree 2 files changed +45
-2
lines changed Expand file tree Collapse file tree 2 files changed +45
-2
lines changed Original file line number Diff line number Diff line change @@ -37,8 +37,8 @@ public function parse(string $string): array
37
37
$ collected = [];
38
38
39
39
for ($ i = 0 ; $ i < $ lineCount ; ++$ i ) {
40
- if (preg_match ('( ^--- \\ s+ (?P<file>\\ S+)) ' , $ lines [$ i ], $ fromMatch ) &&
41
- preg_match ('( ^ \\+ \\+ \\+ \\s+ (?P<file>\\ S+)) ' , $ lines [$ i + 1 ], $ toMatch )) {
40
+ if (preg_match ('# ^---\h+"? (?P<file>[^ \\ v \\ t"]+)# ' , $ lines [$ i ], $ fromMatch ) &&
41
+ preg_match ('# ^ \\+ \\+ \\+ \\h+"? (?P<file>[^ \\ v \\ t"]+)# ' , $ lines [$ i + 1 ], $ toMatch )) {
42
42
if ($ diff !== null ) {
43
43
$ this ->parseFileDiff ($ diff , $ collected );
44
44
Original file line number Diff line number Diff line change @@ -71,6 +71,49 @@ public function testParseWithMultipleChunks(): void
71
71
$ this ->assertCount (4 , $ chunks [2 ]->getLines ());
72
72
}
73
73
74
+ public function testParseWithSpacesInFileNames (): void
75
+ {
76
+ $ content =
77
+ <<<PATCH
78
+ diff --git a/Foo Bar.txt b/Foo Bar.txt
79
+ index abcdefg..abcdefh 100644
80
+ --- a/Foo Bar.txt
81
+ +++ b/Foo Bar.txt
82
+ @@ -20,4 +20,5 @@ class Foo
83
+ const ONE = 1;
84
+ const TWO = 2;
85
+ + const THREE = 3;
86
+ const FOUR = 4;
87
+
88
+ PATCH ;
89
+
90
+ $ diffs = $ this ->parser ->parse ($ content );
91
+
92
+ $ this ->assertEquals ('a/Foo Bar.txt ' , $ diffs [0 ]->getFrom ());
93
+ $ this ->assertEquals ('b/Foo Bar.txt ' , $ diffs [0 ]->getTo ());
94
+ }
95
+
96
+ public function testParseWithSpacesInFileNamesAndTimesamp (): void
97
+ {
98
+ $ content =
99
+ <<<PATCH
100
+ diff --git a/Foo Bar.txt b/Foo Bar.txt
101
+ index abcdefg..abcdefh 100644
102
+ --- "a/Foo Bar.txt" 2020-10-02 13:31:52.938811371 +0200
103
+ +++ "b/Foo Bar.txt" 2020-10-02 13:31:50.022792064 +0200
104
+ @@ -20,4 +20,5 @@ class Foo
105
+ const ONE = 1;
106
+ const TWO = 2;
107
+ + const THREE = 3;
108
+ const FOUR = 4;
109
+ PATCH ;
110
+
111
+ $ diffs = $ this ->parser ->parse ($ content );
112
+
113
+ $ this ->assertEquals ('a/Foo Bar.txt ' , $ diffs [0 ]->getFrom ());
114
+ $ this ->assertEquals ('b/Foo Bar.txt ' , $ diffs [0 ]->getTo ());
115
+ }
116
+
74
117
public function testParseWithRemovedLines (): void
75
118
{
76
119
$ content = <<<END
You can’t perform that action at this time.
0 commit comments