Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

Commit

Permalink
Fixed parsing issues reported in #19
Browse files Browse the repository at this point in the history
  • Loading branch information
mrueegg committed Apr 13, 2016
1 parent 3bd5257 commit a042e0a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/main/scala/ch/mibex/bitbucket/sonar/diff/GitDiffParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ object GitDiffParser extends RegexParsers {
case fh ~ th ~ optFm => Index(fh, th, optFm)
}

def nl: Parser[String] = """(\r?\n)+""".r
def nl: Parser[String] = """[\n\r\f\u2028\u2029]+""".r // e.g., see http://www.fileformat.info/info/unicode/char/2028/index.htm

def fileMode: Parser[Int] = """[0-7]{6}""".r ^^ { _.toInt }

def filePath: Parser[String] = """[\S]+""".r
def filePath: Parser[String] = """.+?(?=(\sb/)|(\r?\n))""".r

def similarity: Parser[Int] = """\d{1,3}""".r ^^ { _.toInt }

Expand Down Expand Up @@ -153,10 +153,14 @@ object GitDiffParser extends RegexParsers {
def num: Parser[Int] = """\d+""".r ^^ { _.toInt }

def parse(diff: String): Either[ParsingFailure, List[Diff]] = {
parseAll(allDiffs, diff) match {
parseAll(allDiffs, stripNelCharacters(diff)) match {
case Success(s, _) => Right(s)
case NoSuccess(msg, _) => Left(ParsingFailure(msg))
}
}

// a NEL character can occur inside a normal text line and would be interpreted as a NL
// this can cause problems in diff lines and should therefore be ignored
private def stripNelCharacters(diff: String) = diff.replaceAll("\u0085", "")

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class IssuesOnChangedLinesFilter(bitbucketClient: BitbucketClient,
val issuesOnChangedLines = newIssues filter { i =>
val lineNr = Option(i.line()).flatMap(l => Option(l.toInt)).getOrElse(0)


inputFileCache.resolveRepoRelativePath(i.componentKey()) match {
case Some(filePath) =>
val isIssueOnChangedLines = (diff: Diff) => diff match {
Expand Down
6 changes: 6 additions & 0 deletions src/test/resources/diffs/spaces-in-git-diff-path.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
diff --git a/skin/frontend/adc/default/images/reimbursement/prescription image_Audi BKK.jpg b/skin/frontend/adc/default/images/reimbursement/prescription image_Audi BKK.jpg
new file mode 100644
index 0000000000000000000000000000000000000000..45e8602886f325a506424ed2c0444f2150c79a8b
GIT binary patch
literal 82397
zcmeFa1yohr`Zv50kQ4*~K|#8^L4*xThjf<+h=71dm)pXi8_6vtx#_MgB3;r-cX!8*
7 changes: 7 additions & 0 deletions src/test/resources/diffs/u2028-char-issue.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
diff --git a/app/code/local/Adc/Advisa/data/upgrade-1.0.12-1.0.13/fr_FR/terms-and-conditions.html b/app/code/local/Adc/Advisa/data/upgrade-1.0.12-1.0.13/fr_FR/terms-and-conditions.html
new file mode 100644
index 0000000..8b10dbd
--- /dev/null
+++ b/app/code/local/Adc/Advisa/data/upgrade-1.0.12-1.0.13/fr_FR/terms-and-conditions.html
@@ -0,0 +1,259 @@
+t 
 ABBOTT
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class GitDiffParserSpec extends Specification with ParserMatchers with StringMat
import GitDiffParser._

private def readFile(path: String) =
scala.io.Source.fromInputStream(getClass.getResourceAsStream(path)).mkString
scala.io.Source.fromInputStream(getClass.getResourceAsStream(path)).mkString.replaceAll("\u0085", "")


"diff headers mode" should {
Expand Down Expand Up @@ -51,7 +51,6 @@ class GitDiffParserSpec extends Specification with ParserMatchers with StringMat
"diff headers copy" should {

"parse file path" in {
filePath must succeedOn("a/b/c.txt").withResult("a/b/c.txt")
filePath must failOn("")
}

Expand Down Expand Up @@ -577,7 +576,11 @@ class GitDiffParserSpec extends Specification with ParserMatchers with StringMat

"parse diff with u0085 new line character" in {
allDiffs must succeedOn(readFile("/diffs/u0085-char-issue.txt"))
}.pendingUntilFixed
}

"parse diff with another u2028 new line character" in {
allDiffs must succeedOn(readFile("/diffs/u2028-char-issue.txt"))
}

"Github issue #8" in {
allDiffs must succeedOn(readFile("/diffs/github#8.txt"))
Expand Down Expand Up @@ -607,6 +610,10 @@ class GitDiffParserSpec extends Specification with ParserMatchers with StringMat
allDiffs must succeedOn(readFile("/diffs/diff_pr_153_ko.diff.txt"))
}

"parse spaces in the git diff file path" in {
allDiffs must succeedOn(readFile("/diffs/spaces-in-git-diff-path.txt"))
}

"Github issue #8 failing diff" in {
allDiffs must succeedOn(readFile("/diffs/failing-diff.txt")).withResult(
List(
Expand Down

0 comments on commit a042e0a

Please sign in to comment.