Skip to content

Commit

Permalink
Fixed NoCommentsYamlLine
Browse files Browse the repository at this point in the history
  • Loading branch information
SherifWaly committed Mar 21, 2017
1 parent 806c3e9 commit eb569a7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
17 changes: 8 additions & 9 deletions src/main/java/com/amihaiemil/camel/NoCommentsYamlLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,21 @@ public int compareTo(final YamlLine other) {

@Override
public String trimmed() {
String string = this.line.trimmed();
String trimmed = this.line.trimmed();
int i = 0;
while(i < string.length()) {
if(string.charAt(i) == '#') {
string = string.substring(0, i);
while(i < trimmed.length()) {
if(trimmed.charAt(i) == '#') {
trimmed = trimmed.substring(0, i);
break;
} else if(string.charAt(i) == '"') {
} else if(trimmed.charAt(i) == '"') {
i++;
while(i < string.length() && string.charAt(i) != '"') {
while(i < trimmed.length() && trimmed.charAt(i) != '"') {
i++;
}
} else {
i++;
}
i++;
}
return string.trim();
return trimmed.trim();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,18 @@ public void trimsCommentsLine() {
@Test
public void trimsCommentsAtEndOfLine() {
YamlLine noComments = new NoCommentsYamlLine(
new RtYamlLine(" this isn't comment #here is the comment", 1)
new RtYamlLine(" \"this isn't comment\" #here is the comment", 1)
);
MatcherAssert.assertThat(
noComments.trimmed(), Matchers.is("this isn't comment")
noComments.trimmed(), Matchers.is("\"this isn't comment\"")
);
}

/**
* NoCommentsYamlLine doesn't remove # escaped in a string.
* NoCommentsYamlLine doesn't remove escaped # in a string.
*/
@Test
public void doesnotTrimsEscapedHash() {
public void doesNotTrimsEscapedHash() {
YamlLine noComments = new NoCommentsYamlLine(
new RtYamlLine(" \"value = #5\" ", 2)
);
Expand Down

0 comments on commit eb569a7

Please sign in to comment.