-
-
Notifications
You must be signed in to change notification settings - Fork 86
Allow spaces in parser #105
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
Allow spaces in parser #105
Conversation
Hi and nice find! Just wondering if this can be tweaked even more to something like; |
fab05ce
to
68f1ae7
Compare
Hi @SpacePossum Good suggestions! I changed the commit. I also added tabs to the exclusion list. This test also has timestamps after the filenames (with a leading tab). If tabs are being used for filenames (why? 😄 ) it gets represented as
Would this cover everything? |
Good catch on the timestamps! I really wished "they" formalized the diff file format in some standard :D |
Any idea why the checks failed? |
444bf51
to
68f1ae7
Compare
diff --git a/src/Parser.php b/src/Parser.php
index 6090e81..cc9e388 100644
--- a/src/Parser.php
+++ b/src/Parser.php
@@ -37,8 +37,8 @@ public function parse(string $string): array
$collected = [];
for ($i = 0; $i < $lineCount; ++$i) {
- if (preg_match('(^---\\s+(?P<file>\\S+))', $lines[$i], $fromMatch) &&
- preg_match('(^\\+\\+\\+\\s+(?P<file>\\S+))', $lines[$i + 1], $toMatch)) {
+ if (preg_match('#^---\h+"?(?P<file>[^\\v\\t"]+)#', $lines[$i], $fromMatch) &&
+ preg_match('#^\\+\\+\\+\\h+"?(?P<file>[^\\v\\t"]+)#', $lines[$i + 1], $toMatch)) {
if ($diff !== null) {
$this->parseFileDiff($diff, $collected);
diff --git a/tests/ParserTest.php b/tests/ParserTest.php
index 7623970..30d9fe2 100644
--- a/tests/ParserTest.php
+++ b/tests/ParserTest.php
@@ -166,4 +166,45 @@ public function diffProvider(): array
],
];
}
+
+ public function testParseWithSpacesInFileNames(): void
+ {
+ $content =
+<<<PATCH
+diff --git a/Foo Bar.txt b/Foo Bar.txt
+index abcdefg..abcdefh 100644
+--- a/Foo Bar.txt
++++ b/Foo Bar.txt
+@@ -20,4 +20,5 @@ class Foo
+ const ONE = 1;
+ const TWO = 2;
++ const THREE = 3;
+ const FOUR = 4;
+PATCH;
+
+ $diffs = $this->parser->parse($content);
+
+ $this->assertEquals('a/Foo Bar.txt', $diffs[0]->getFrom());
+ $this->assertEquals('b/Foo Bar.txt', $diffs[0]->getTo());
+ }
+
+ public function testParseWithSpacesInFileNamesAndTimestamp(): void
+ {
+ $content =
+ <<<PATCH
+diff --git a/Foo Bar.txt b/Foo Bar.txt
+index abcdefg..abcdefh 100644
+--- "a b.txt" 2020-10-02 13:31:52.938811371 +0200
++++ "a c.txt" 2020-10-02 13:31:50.022792064 +0200
+@@ -20,4 +20,5 @@ class Foo
+ const ONE = 1;
+ const TWO = 2;
++ const THREE = 3;
+ const FOUR = 4;
+PATCH;
+ $diffs = $this->parser->parse($content);
+
+ $this->assertEquals('a b.txt', $diffs[0]->getFrom());
+ $this->assertEquals('a c.txt', $diffs[0]->getTo());
+ }
} Hi again! Above will allow for About the test failing, not sure as it doesn't seem related to your changes. Maybe try to kick them again by committing something to the PR as the composer dependencies might be stuck in the cache. |
The from and to in diffs did not include the full path name when spaces are being used. This change allows spaces in the file paths as well (no tabs).
68f1ae7
to
3c9aefe
Compare
@SpacePossum Good catch! I implemented your changes and the tests pass. Do you know how I get that diff output (with timestamps and surrounding quotes)? |
I made the diff examples using If you are generating diffs using the project you can use this output builder and pass the file name with quotes: The test failures are confusing to me, maybe Sebastian can help out with the setup when he has some time. |
Ping @sebastianbergmann whenever you've got time, please let us know how we can help out, thanks! :) |
Maybe @localheinz has some insight why GitHub Actions (sometimes) fail for pull requests on my projects. @SpacePossum If this is looks okay to you, then it is okay for me as well. I'll merge this which should (fingers crossed) give us a useful GitHub Actions build. |
thanks so much :) thanks for the PR @Matth-- 👍 |
Could this be the composer root version problem again? |
Could be, don't know. Sorry! |
The from and to in diffs did not include the full path name when
spaces are being used. This change allows spaces in the file paths
as well (no tabs).