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
[JENKINS-27505] Preserve an empty line at the beginning of a textarea #1612
Changes from 4 commits
979ddba
d135db1
9794f02
236632b
f0a88e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ import org.kohsuke.stapler.QueryParameter | |
|
||
import javax.inject.Inject | ||
|
||
import static org.junit.Assert.* | ||
|
||
/** | ||
* | ||
* | ||
|
@@ -70,4 +72,61 @@ class TextAreaTest { | |
} | ||
|
||
} | ||
|
||
@Test | ||
public void testText() { | ||
def TEXT_TO_TEST = "some\nvalue\n"; | ||
def p = j.createFreeStyleProject(); | ||
def target = new TextareaTestBuilder(TEXT_TO_TEST); | ||
p.buildersList.add(target); | ||
j.configRoundtrip(p); | ||
j.assertEqualDataBoundBeans(target, p.getBuildersList().get(TextareaTestBuilder.class)); | ||
} | ||
|
||
@Issue("JENKINS-27505") | ||
@Test | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW it would save test execution time to collapse these three test cases. |
||
public void testTextBeginningWithEmptyLine() { | ||
def TEXT_TO_TEST = "\nbegin\n\nwith\nempty\nline\n\n"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about two initial newlines? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (resolved) |
||
def p = j.createFreeStyleProject(); | ||
def target = new TextareaTestBuilder(TEXT_TO_TEST); | ||
p.buildersList.add(target); | ||
j.configRoundtrip(p); | ||
j.assertEqualDataBoundBeans(target, p.getBuildersList().get(TextareaTestBuilder.class)); | ||
} | ||
|
||
@Issue("JENKINS-27505") | ||
@Test | ||
public void testTextBeginningWithTwoEmptyLines() { | ||
def TEXT_TO_TEST = "\n\nbegin\n\nwith\ntwo\nempty\nline\n\n"; | ||
def p = j.createFreeStyleProject(); | ||
def target = new TextareaTestBuilder(TEXT_TO_TEST); | ||
p.buildersList.add(target); | ||
j.configRoundtrip(p); | ||
j.assertEqualDataBoundBeans(target, p.getBuildersList().get(TextareaTestBuilder.class)); | ||
} | ||
|
||
public static class TextareaTestBuilder extends Builder { | ||
private text; | ||
|
||
@DataBoundConstructor | ||
TextareaTestBuilder(String text) { | ||
this.text = text; | ||
} | ||
|
||
public String getText() { return text; } | ||
|
||
@TestExtension | ||
public static class DescriptorImpl extends BuildStepDescriptor<Builder> { | ||
@Override | ||
boolean isApplicable(Class<? extends AbstractProject> jobType) { | ||
return true; | ||
} | ||
|
||
@Override | ||
String getDisplayName() { | ||
return this.class.name; | ||
} | ||
} | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<!-- no config --> | ||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"> | ||
<f:entry field="text" title="${%Text}"> | ||
<f:textarea/> | ||
</f:entry> | ||
</j:jelly> |
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.
Jelly doesn't accept backslashes (like
\n
)...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.
jelly and groovy has ability to unescape text, feel free to try.
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 tried this in jelly
and that resulted like this:
backslashes doesn't seem handled.
Maybe I need another way to handle control characters.
Would you show me some examples to have jelly unescape texts?
I could not find good documentations for jelly...
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.
Documentation for Jelly is weak. Generally speaking if you are trying to do anything subtle you have to switch to Groovy to get more control.