-
Notifications
You must be signed in to change notification settings - Fork 317
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
Normalization of Line Terminators in Xbase strings #3004
Conversation
Looks like I haven't gotten the replacement correctly: it also leads to this unwanted difference: I thought this test would check that efa5aa1#diff-7217ccbb0669983e16ca897570a543e7ee1bfb23a156c11fe9425cc5db1536baR2210 |
OK, this fadf9c7 reproduces the problem and fixes it |
@szarnekow the build fails. I guess I haven't override all the needed methods in the custom value converter? |
public static class WindowsEOLsAwareSTRINGValueConverter extends STRINGValueConverter { | ||
@Override | ||
public String toValue(String string, INode node) { | ||
return Strings.toUnixLineSeparator(super.toValue(string, node)); |
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.
It's an interesting case. I guess we want to treat an explicit \r
in the string literal different from a regular windows newline. I've to think about it.
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.
cf
public static void main(String[] args) {
String s = """
some\r\nstring""";
System.out.println(s);
System.out.println(s.length());
System.out.println('\r' == s.charAt(4));
}
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.
@szarnekow a quick thought: I guess the original string should be normalized before passing it to super, not afterward as I'm doing now
And the current implementation is still not correct, since we have this result: @Test
public void testStringLiteralWithCarriageReturn3_Issue2293() throws Exception {
compilesTo(
"{\"astring\".toString.replaceAll(\"\\r\\n\", \"\\n\");}",
"return \"astring\".toString().replaceAll(\"\\n\", \"\\n\");");
} The "\r" from the original source code is removed, which is wrong! |
Passing the already normalized string to super: public static class WindowsEOLsAwareSTRINGValueConverter extends STRINGValueConverter {
@Override
public String toValue(String string, INode node) {
return super.toValue(Strings.toUnixLineSeparator(string), node);
}
} leads to the expected test result: @Test
public void testStringLiteralWithCarriageReturn3_Issue2293() throws Exception {
compilesTo(
"{\"astring\".toString.replaceAll(\"\\r\\n\", \"\\n\");}",
"return \"astring\".toString().replaceAll(\"\\r\\n\", \"\\n\");");
} |
@szarnekow concerning the failing tests in Xtend, I think I found the culprit: the way I customized the Xbase string converter did not allow for customizations, and the Xtend customizations were not picked anymore. This should do: 9b8cc60 P.S., do you think it's worthwhile to rename the Xtend |
@szarnekow I rebased the PR This is still to be done if you think it's feasible:
|
Yes
Yes |
@szarnekow rebased and renamed the Xtend string value converter. |
@@ -912,7 +912,7 @@ public abstract class AbstractXbaseEvaluationTest extends Assert { | |||
} | |||
|
|||
@Test public void testStringLiteral_03() throws Exception { | |||
assertEvaluatesTo("lite\r\nr\\al", "'lite\r\nr\\\\al'"); | |||
assertEvaluatesTo("lite\nr\\al", "'lite\r\nr\\\\al'"); |
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.
Please add tests here that use the Java string literal \\r\\n
and \\n
respectively. These should remain untouched, since they don't rely on the line endings of the compilation unit but use backlash-r and backslash-n respectively.
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.
@szarnekow this one d7c67a3 ?
Yes, we have a duplicated AbstractXbaseEvaluationTest ;)
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 knew that I saw it somewhere ... damn it :)
Thanks!
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.
Please add a reminder for the N&N
Closes #2293