-
Notifications
You must be signed in to change notification settings - Fork 29
Fixed CND parsing under Windows OS #48
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
Conversation
…Path ~ updated unit test
$reader->rewind(); | ||
|
||
return true; | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else is not needed here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Just removed it.
thank you! can you have a look at the failing test on Travis? @dbu should have a look at you method rename |
Sorry, didn't noticed the failing test. |
While checking the failed tests I realized there's an issue with my current implementation. |
… of the EOL character
public function isEol() | ||
{ | ||
$current = $this->current(); | ||
$marker = $this->getEolMarker(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think we need a field and getter for the eol, rather use the PHP_EOL directly below. end-of-line is handled by php for us, i think that is good enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the issue is that PHP_EOL is different depending on which OS you are running the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah ok, you wanted the test to test both. then lets just have a member variable but not use a getter method each time.
and lets have the constructor accept an optional $eolMarker that defaults to PHP_EOL. it could be useful for somebody in edge cases.
thanks for this PR. i commented on some naming things. is the reason you ran into this issue in the first place that your git client converted the line endings? i fear that we still can see problems after this fix. what would happen if we always check for both types of line endings, and maybe add the apple OS endings as well? might be the most flexible approach. btw, impressive that after 30 years of PC we still see this stupid problem :-( |
The look-ahead is solved. The issue I came upon was invoked because of the hardcoded EOL. It was set like "\n" and for Windows is "\r\n". Later on the process of parsing there was the assumption that the EOL is a single character, which obviously is not true, so the code failed to parse the string. I'm struggling at the GenericScanner now. There are some naming wtfs that are pretty confusing. Once I'm done with the GenericScanner, I believe we would be able to handle whatever EOL we like. LF, CR, CR+LF, LF+CR, you name it. IMHO, it is a design fail that caused the issue. I had the idea of converting the EOL within the reader constructor. Any thoughts on that? |
maybe we could simply string replace all possible formats to |
the constructor then would be
|
Exactly my point. I was not aware whether the CRLF would be used anywhere inside the document and couldn't decide by myself to do such conversion. |
@@ -54,7 +88,7 @@ public function testGetNextChar() | |||
break; | |||
} | |||
|
|||
//var_dump('Expected:' . $this->chars[$i] . ', found: ' . $peek); | |||
// var_dump('Expected:' . $this->chars[$i] . ', found: ' . $peek); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets remove commented out code
i don't expect any problems, lets convert everything to the one-char |
@dinamic can you do the cleanup and convert all cnd files to unix line endings in the constructor, before further handling them? |
@dbu In Windows (at least Windows 7) in PHP global constant PHP_EOL by default equal CRLF, not LF. Accordingly, any comparison between currentChar() and PHP_EOL not work, because PHP_EOL contains 2 chars. In this case, it does not matter what kind of line breaks in the cnd files. |
I see the most reasonable solution to convert all line breaks in cnd to the LF and replace PHP_EOL in all comparisons also to LF. |
yes, thats exactly what we should do. i hope dinamic can do it - if you don't want to wait you could fork his repo and finish it and create a new PR |
superseded by #51 |
Thanks for contributing @relo-san. I didn't had the time to finish my fix. |
CND data was not correctly parsed while using Windows OS.
The issue was caused by the different line endings between the operating systems.
I came up with a fix and updated the unit tests to test both Windows and Unix line endings.
I've found some discrepancies inside the FileReader class, so it is updated as well.
This commit fixes: https://github.com/symfony-cmf/symfony-cmf-standard/issues/21