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

Fix newline behavior for template rendering on Windows, including tests #570

Closed
wants to merge 5 commits into from

Conversation

@yunyu
Copy link
Contributor

yunyu commented Mar 26, 2017

Several users in the IRC (@ivanovdns, @alexlehm) reported that all vertx-template-engines tests with newlines were failing on Windows.

This is because Git on Windows checks out as CRLF by default, and the template engines in question just use the provided line endings. The fact that Windows line endings are ever returned is an issue in the implementation, as usage of '\n' is extremely prevalent throughout the Vert.x codebase, including the tests. We can't just use System.getProperty("line.separator") in the tests, as the behavior isn't reliable and some developers may disabled autocrlf.

These commits fix this behavior by introducing a performant CRLF-to-LF converter adapted from Netty's ByteBufInputStream in Utils#readFileToString, and has the side effect of fixing all the template tests on Windows. For the latter reason, no additional tests should be needed.

If the behavior shouldn't be changed, a form of line ending detection should be done in the tests.

@vietj vietj added the to review label Mar 26, 2017
@yunyu yunyu force-pushed the yunyu:fix-template-tests-on-windows branch from ab88b66 to 0353175 Mar 26, 2017
@yunyu yunyu force-pushed the yunyu:fix-template-tests-on-windows branch 2 times, most recently from 39c250b to 8dbea67 Mar 26, 2017
This fixes tests and template rendering behavior on Windows
@yunyu yunyu force-pushed the yunyu:fix-template-tests-on-windows branch 3 times, most recently from 383df18 to e60484a Mar 26, 2017
@yunyu yunyu force-pushed the yunyu:fix-template-tests-on-windows branch 2 times, most recently from 62674a4 to 6f0ef58 Mar 26, 2017
@yunyu yunyu force-pushed the yunyu:fix-template-tests-on-windows branch 3 times, most recently from 4ea711d to 53e4ba9 Mar 26, 2017
@yunyu yunyu force-pushed the yunyu:fix-template-tests-on-windows branch from 53e4ba9 to c77c915 Mar 26, 2017
@alexlehm
Copy link
Contributor

alexlehm commented Mar 27, 2017

+1 from me

@ivanovdns
Copy link

ivanovdns commented Mar 27, 2017

@yunyul, @alexlehm thank you guys!

@pmlopes pmlopes self-requested a review Mar 29, 2017
Copy link
Member

pmlopes left a comment

We can't change the internal behavior of the readFileToString, either it should be handled in the test side or a extra method should be provided.

/*
Reads from file or classpath
Reads from file or classpath using the default charset, replacing CRLF line endings with LF ones

This comment has been minimized.

Copy link
@pmlopes

pmlopes Mar 29, 2017

Member

This will be a behavior breaking change and I'm not sure it is correct. One can use the readFileToString to load anything, including, say for example, yaml, json, etc... where in most cases replacing line endings does not introduce side effects, but it could do with some formats.

return buff.toString(charset);
}
int buffLen = buff.length();
ByteBuf byteBuf = buff.getByteBuf();

This comment has been minimized.

Copy link
@pmlopes

pmlopes Mar 29, 2017

Member

What will be the advantage of using the underlying netty API here, IMO we should keep with the vert.x API since it would address eventual changes underlying and later we're just iterating all bytes so one could achieve the same with a loop on the vert.x buffer.

@alexlehm
Copy link
Contributor

alexlehm commented Mar 29, 2017

@yunyul can you please take a look?

@yunyu
Copy link
Contributor Author

yunyu commented Mar 29, 2017

I'm going to close this and split this up into two pull requests if the behavior can't be changed:

  • De-duplication of code in the template engines (#574)

  • Line ending normalization for tests (#575)

@yunyu yunyu closed this Mar 29, 2017
@vietj vietj removed the to review label Mar 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.