diff options
author | Freddy Mallet <freddy.mallet@gmail.com> | 2011-04-17 00:27:30 +0200 |
---|---|---|
committer | Freddy Mallet <freddy.mallet@gmail.com> | 2011-04-17 00:27:30 +0200 |
commit | 1d7e1e31407a49f365b811145b566754250e416a (patch) | |
tree | 457863402d1e56dea531eb786723d62836719775 /sonar-colorizer | |
parent | 6b366e15d372189aebe827b337abb2fe8433927e (diff) | |
download | sonarqube-1d7e1e31407a49f365b811145b566754250e416a.tar.gz sonarqube-1d7e1e31407a49f365b811145b566754250e416a.zip |
fix SONAR-2295 : Line number representation in source code view are wrong for files that use mixed line endings
Diffstat (limited to 'sonar-colorizer')
-rw-r--r-- | sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlDecorator.java | 17 | ||||
-rw-r--r-- | sonar-colorizer/src/test/java/org/sonar/colorizer/HtmlDecoratorTest.java | 2 |
2 files changed, 8 insertions, 11 deletions
diff --git a/sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlDecorator.java b/sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlDecorator.java index 0d0b4386118..5e4e2e512d8 100644 --- a/sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlDecorator.java +++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlDecorator.java @@ -30,7 +30,7 @@ public class HtmlDecorator extends Tokenizer { private static final String CSS_PATH = "/sonar-colorizer.css"; private HtmlOptions options; - private int lineId = 1; + private int lineId; private static final int LF = (int) '\n'; private static final int CR = (int) '\r'; @@ -76,18 +76,15 @@ public class HtmlDecorator extends Tokenizer { @Override public boolean consume(CodeReader code, HtmlCodeBuilder codeBuilder) { - int currentChar = code.peek(); - - if (currentChar == LF) { - codeBuilder.appendWithoutTransforming(getTagAfter()); - codeBuilder.appendWithoutTransforming(getTagBefore()); - } - - if (currentChar == LF || currentChar == CR) { + int lineNumber = code.getLinePosition(); + if (code.peek() == LF || code.peek() == CR) { code.pop(); + if (lineNumber != code.getLinePosition()) { + codeBuilder.appendWithoutTransforming(getTagAfter()); + codeBuilder.appendWithoutTransforming(getTagBefore()); + } return true; } - return false; } diff --git a/sonar-colorizer/src/test/java/org/sonar/colorizer/HtmlDecoratorTest.java b/sonar-colorizer/src/test/java/org/sonar/colorizer/HtmlDecoratorTest.java index a49dafe025b..916640de168 100644 --- a/sonar-colorizer/src/test/java/org/sonar/colorizer/HtmlDecoratorTest.java +++ b/sonar-colorizer/src/test/java/org/sonar/colorizer/HtmlDecoratorTest.java @@ -80,7 +80,7 @@ public class HtmlDecoratorTest { public void shouldAddTagsBetweenEachLine() { HtmlOptions options = new HtmlOptions().setGenerateTable(true).setGenerateHtmlHeader(false); HtmlDecorator decorator = new HtmlDecorator(options); - CodeReader code = new CodeReader("\n\r\n"); + CodeReader code = new CodeReader("\r\n\r"); HtmlCodeBuilder output = new HtmlCodeBuilder(); output.appendWithoutTransforming(decorator.getTagBeginOfFile()); |