r106113 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106112‎ | r106113 | r106114 >
Date:22:03, 13 December 2011
Author:hashar
Status:ok
Tags:
Comment:
parseChunkDelimiter is now newline agnostic

Under Windows, newline is \r\n. Thus we were passing a chunk delimiter ending
with a remaining \r and the chunk was never recognized. That caused an
exception to be thrown when CodeReview is installed on a Windows server.

rtrim() happilly makes this function agnostic.

added two tests cases to make sure we do not choke anymore on this issue.

Fix r94951
Modified paths:
  • /trunk/extensions/CodeReview/backend/DiffHighlighter.php (modified) (history)
  • /trunk/extensions/CodeReview/tests/DiffHighlighterTest.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/backend/DiffHighlighter.php
@@ -294,6 +294,8 @@
295295 * @return array with the four values above as an array
296296 */
297297 static function parseChunkDelimiter( $chunkHeader ) {
 298+ $chunkHeader = rtrim( $chunkHeader );
 299+
298300 # regex snippet to capture a number
299301 $n = "(\d+)";
300302
Index: trunk/extensions/CodeReview/tests/DiffHighlighterTest.php
@@ -2,6 +2,26 @@
33
44 class CodeDiffHighlighterTest extends MediaWikiTestCase {
55
 6+ function testParseChunksFromWindowsDiff() {
 7+ try {
 8+ CodeDiffHighlighter::parseChunkDelimiter(
 9+ "@@ -1,3 +1,4 @@\r\n"
 10+ );
 11+ } catch( Exception $e ) {
 12+ $this->fail( "parseChunkDelimiter() could not parse a chunk finishing with '\\r\\n' This is happening on Windows" );
 13+ }
 14+ }
 15+
 16+ function testParseChunksFromUnixDiff() {
 17+ try {
 18+ CodeDiffHighlighter::parseChunkDelimiter(
 19+ "@@ -1,3 +1,4 @@\n"
 20+ );
 21+ } catch( Exception $e ) {
 22+ $this->fail( "parseChunkDelimiter() could not parse a chunk finishing with '\\n' This is happening on Unix systems" );
 23+ }
 24+ }
 25+
626 /**
727 * @dataProvider provideUnifiedDiffChunksDelimiters
828 */

Follow-up revisions

RevisionCommit summaryAuthorDate
r112091tests not throwing an exception are successes...hashar08:58, 22 February 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r94951new method to parse chunk delimiters...hashar21:28, 18 August 2011

Status & tagging log