Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Respecting line endings in AnnotationScanner #6676

Closed
wants to merge 5 commits into from
Closed

Respecting line endings in AnnotationScanner #6676

wants to merge 5 commits into from

Conversation

waltertamboer
Copy link
Contributor

The annotation scanner only checked for line feeds ("\n"), carriage returns were not respected causing problems on files that were contained Mac or Windows line endings ("\r" or "\r\n").

@@ -160,7 +160,7 @@ protected function tokenize()
}
$currentChar = $stream[$streamIndex];
$matches = array();
$currentLine = (preg_match('#(.*)\n#', $stream, $matches, null, $streamIndex) === 1) ? $matches[1] : substr($stream, $streamIndex);
$currentLine = (preg_match('#(.*?)(?:\n|\r|\r\n)#', $stream, $matches, null, $streamIndex) === 1) ? $matches[1] : substr($stream, $streamIndex);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be simplified: (?:\n|\r\n?)

@Ocramius
Copy link
Member

@waltertamboer needs a test case with a test asset with non-unix newlines, I suppose.

@Ocramius
Copy link
Member

Can actually be crafted in the test case by explicitly using escape sequences like "\r\n" or "\n\r" depending on tested system

@waltertamboer
Copy link
Contributor Author

@Ocramius I'm more than happy to update this PR but it's a bit unclear what you want me to do.

I probably can't create a test file that has other line endings because when people check out the code and git changes line endings, the test will break.

@Ocramius
Copy link
Member

@waltertamboer what is needed is a test asset with DOS/Windows line endings, and a respective test :-)

@waltertamboer
Copy link
Contributor Author

@Ocramius Done. Sorry for the delay. I updated the existing unit test so that it is tested with all type of line endings.

@Ocramius Ocramius added this to the 2.3.5 milestone Jan 18, 2015
@Ocramius
Copy link
Member

@waltertamboer thanks!

@Ocramius Ocramius self-assigned this Jan 18, 2015
Ocramius added a commit that referenced this pull request Feb 2, 2015
@Ocramius Ocramius closed this in 948f917 Feb 2, 2015
@Ocramius
Copy link
Member

Ocramius commented Feb 2, 2015

@waltertamboer merged, thanks.

master: 948f917
develop: fc4676a

@Ocramius
Copy link
Member

Ocramius commented Feb 2, 2015

@waltertamboer one remark, please never ever EVER merge master or develop into a feature/ or hotfix/ branch, as it messes with git bisect if a problem arises in future.

Instead, use git rebase, and also be very careful to never git pull without also using the --ff-only flag, as pull does automatically merge otherwise.

I simply cherry-picked the commits out of this PR, so it doesn't result as merged, but just as closed.

Thanks for sorting this out, very simple and clean fix :-)

@waltertamboer
Copy link
Contributor Author

Lesson learned. Thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants