Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #1612 from ikedam/feature/JENKINS-27505_TextareaSt…
Browse files Browse the repository at this point in the history
…artsEmptyLine

[JENKINS-27505] Preserve an empty line at the beginning of a textarea
  • Loading branch information
oleg-nenashev committed Nov 15, 2015
2 parents 0fe7c69 + f0a88e6 commit b23b3cf
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/src/main/resources/lib/form/textarea.jelly
Expand Up @@ -89,6 +89,7 @@ THE SOFTWARE.
readonly="${attrs.readonly}"
codemirror-mode="${attrs['codemirror-mode']}"
codemirror-config="${attrs['codemirror-config']}">
<j:if test="${value != null &amp;&amp; !empty(value.toString()) &amp;&amp; (value.toString().codePointAt(0) == 10 || value.toString().codePointAt(0) == 13)}"><j:whitespace>&#10;</j:whitespace></j:if>
<st:out value="${value}" />
</textarea>
<j:if test="${customizedFields != null and attrs.field != null and value != default}">
Expand Down
60 changes: 60 additions & 0 deletions test/src/test/groovy/lib/form/TextAreaTest.groovy
Expand Up @@ -14,6 +14,8 @@ import org.kohsuke.stapler.QueryParameter

import javax.inject.Inject

import static org.junit.Assert.*

/**
*
*
Expand Down Expand Up @@ -65,4 +67,62 @@ class TextAreaTest {
}

}

@Issue("JENKINS-27505")
@Test
public void testText() {
T1:{
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));
}

// test for a textarea beginning with a empty line.
T2:{
def TEXT_TO_TEST = "\nbegin\n\nwith\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));
}

// test for a textarea beginning with two empty lines.
T3:{
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;
}
}

}
}
@@ -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>

0 comments on commit b23b3cf

Please sign in to comment.