diff --git a/_test/tests/inc/io_replaceinfile.test.php b/_test/tests/inc/io_replaceinfile.test.php
index 597138a2000c49d5123c59a502d09573b9eb6bf9..452ed740108fe48cf0351f358a466ab1796487fd 100644
--- a/_test/tests/inc/io_replaceinfile.test.php
+++ b/_test/tests/inc/io_replaceinfile.test.php
@@ -94,4 +94,15 @@ class io_replaceinfile_test extends DokuWikiTest {
         $this->assertTrue(io_replaceInFile($file, "Delete\012", "Replace\012", false, -1));
         $this->assertEquals("The\012Replace\01201Delete\01202Delete\012Test\012", io_readFile($file), "Edge case: old line is a match for parts of other lines");
     }
+
+    /**
+     * Test passing an invalid parameter.
+     *
+     * @expectedException PHPUnit_Framework_Error_Warning
+     */
+    function test_badparam()
+    {
+        /* The empty $oldline parameter should be caught before the file doesn't exist test. */
+        $this->assertFalse(io_replaceInFile(TMP_DIR.'/not_existing_file.txt', '', '', false, 0));
+    }
 }
diff --git a/inc/io.php b/inc/io.php
index 4c7fb094f99bb4df619db5f61ca5ffec085d172b..6d3c2004767b920df9b80a91b61358556632bc09 100644
--- a/inc/io.php
+++ b/inc/io.php
@@ -298,6 +298,11 @@ function io_saveFile($file, $content, $append=false) {
  * @return bool true on success
  */
 function io_replaceInFile($file, $oldline, $newline, $regex=false, $maxlines=0) {
+    if ((string)$oldline === '') {
+        trigger_error('$oldline parameter cannot be empty in io_replaceInFile()', E_USER_WARNING);
+        return false;
+    }
+
     if (!file_exists($file)) return true;
 
     io_lock($file);